{"id":22985429,"url":"https://github.com/lordubuntu/adventofcode2023","last_synced_at":"2025-06-21T10:37:49.479Z","repository":{"id":210443790,"uuid":"726579399","full_name":"LordUbuntu/adventofcode2023","owner":"LordUbuntu","description":"My solutions to this year's Advent of Code","archived":false,"fork":false,"pushed_at":"2024-04-14T02:57:53.000Z","size":84,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T02:16:37.499Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LordUbuntu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-02T19:20:47.000Z","updated_at":"2023-12-05T00:57:41.000Z","dependencies_parsed_at":"2023-12-15T06:24:37.167Z","dependency_job_id":"bf00d671-cbff-43a1-8565-367a3881e700","html_url":"https://github.com/LordUbuntu/adventofcode2023","commit_stats":null,"previous_names":["lordubuntu/advent-of-code-2023"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordUbuntu%2Fadventofcode2023","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordUbuntu%2Fadventofcode2023/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordUbuntu%2Fadventofcode2023/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordUbuntu%2Fadventofcode2023/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LordUbuntu","download_url":"https://codeload.github.com/LordUbuntu/adventofcode2023/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246802627,"owners_count":20836373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-15T03:32:00.159Z","updated_at":"2025-04-02T11:13:06.185Z","avatar_url":"https://github.com/LordUbuntu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Advent of Code 2023\n\nMy solutions to this year's Advent of Code\n\n## Day 1\n\n### Part 1\n\nThe goal is to read the first and last digit of each string, add them together, and return the total.\n\nTo do this, we:\n* read each `string` in from the specified `filename`\n* starting on `index` 0, we iterate over the length of `string`\n  * each iteration, we get the character at the current `index`\n  * if the character is a digit we record that as the 10s digit\n  * otherwise we record the current digit as the 1s digit\n* Thus we get the first and last digit, which we join together to make a single `number`\n* Finally, we convert that string representation to an integer and add it to the `total`\n* return `total`\n\n### Part 2\n\nThis time we operate by the same principle but with a sliding window to match against substrings (number words) in addition to matching single digits. \n\nTo do this we:\n* utilize `index` to point to the start of the window\n  * check if the character in `string` at `index` is a digit\n    * if it is\n      * record the digit like in part one and continue\n    * otherwise\n      * iterate over the dictionary of number words greedily (from shortest)\n        * if all characters match, record the equivalent digit as in part 1\n* finally, join the number, add its value to `total`, and return `total`\n\n### Comments\n\nInterestingly both of these solutions are single-pass.\n\nThe implementation(s) can be found in [Day 1]().\n\n\n\n## Day 2\n\n### Part 1\n\nThis one is trivial. We only need to check if the limits of red, green, or blue cubes\nwas violated at any one time (if there were any occurrences of them exceeding 12, 13,\nand 14 respectively). Then we just tally the total of the id's of all games which did\nnot.\n\nTo do this we:\n* read each line, parsing red, green, and blue `counts` along with the `id` number\n  * if any `count` for any `color` exceeds its maximum\n    * continue to next game\n  * otherwise\n    * add game `id` to `total`\n* return `total`\n\n### Part 2\n\nThis one is even easier! To find the minimum possible number of red, green, and blue\ncubes in the bag, we just need to find the maximum occurrences of each. Then to\ncalculate the power we just do a multiply-reduce to get the product of the three, then\nadd that to the total!\n\nTo do this we:\n* read each line and parse into\n  `counts` and `id` as before\n  * if any `count` for any `color` exceeds its previous maximum, update its maximum\n  * calculate the power of the set of cubes using a reduce with the multiply function\n  * add that to the `total`\n* return `total`\n\n\n\n## Day 3\n\n### Part 1\n\nThis problem reminds me of the toboggan slope one! To do that we can essentially use the same logic of modulo and multiplication to represent the 2D grid as a 1D array.\nOne potential way to accomplish this is with a BFS of depth 1 around any digit characters. This solution might be more elegant, requiring less repeat checks than the next idea down. But its time complexity of O(V + E) may not be optimal.\nAnother may be to do a simple sweep, whenever we encounter a digit we add it to a queue. We use some clever 1D \"matrix\" maths to check the tiles directly above, below, left, and right of the current digit for any non-digit non-'.' characters. If we reach the end of a number (string of digits) without encountering any we empty the queue. If we do, then we join the digits together in the correct order (thus the queue), add that to the total, and continue with our now empty queue to the next one. This may be simpler that a BFS and be done in O(n).\n\nThe principle is basic: find all \"islands\" of digits, then check adjacent \"tiles\" for any \"non-'.'\" characters. Add those together. Return.\n\nI'll take a nap and think about it...\n\nPlan:\n* sweep once across the \"grid\" as a string from top left to bottom right\n  * if the current char is '.'\n    * if the number was flagged as a part number (adjacent symbols)\n      * convert queue of digits to int and add it to total\n    * part number flag is false\n    * empty digit queue\n    * continue\n  * if the current char is a digit\n    * add digit to queue\n  * if the current char is not a digit or '.'\n    * part number flag is true\n  * check adjacent tiles for current char for non-digit non-'.' char\n    * if so, part number flag is true\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flordubuntu%2Fadventofcode2023","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flordubuntu%2Fadventofcode2023","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flordubuntu%2Fadventofcode2023/lists"}