|
| 1 | +# Advent of Code 2023 |
| 2 | + |
| 3 | +This is a collection of solutions to the |
| 4 | +[Advent of Code 2023](https://adventofcode.com/2023) programming problems |
| 5 | +implemented in the C programming language. I have done my best to minimize time |
| 6 | +complexity and running time. |
| 7 | + |
| 8 | +Some of the more complex problems were implemented in a |
| 9 | +[higher-level programming language](ref/) before being converted to C. The |
| 10 | +equivalent code is included here as a reference. |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +These programs are cross-platform, having been tested on Windows and Linux |
| 15 | +operating systems. |
| 16 | + |
| 17 | +**Important:** Do not use Windows-style line endings (`CR LF`, i.e. `\r\n`). |
| 18 | +Only use Unix-style line endings (`LF`, i.e. `\n`). |
| 19 | + |
| 20 | +**Important:** I have tested each program on the example test cases and two |
| 21 | +puzzle input files - not a large sample size! I have avoided assumptions about |
| 22 | +the input, sometimes even at the cost of performance. However, to avoid memory |
| 23 | +allocation, all buffers have fixed sizes. Ensure that all buffers (see `#define` |
| 24 | +statements) have sufficient capacity before running. Not doing so could result |
| 25 | +in a stack smashing, segmentation fault, or worse. |
| 26 | + |
| 27 | +## Summary |
| 28 | + |
| 29 | +**Note:** The times below are expressed as orders of magnitude, not precise |
| 30 | +figures. For example, a time of 0.00010 seconds indicates an average running |
| 31 | +time between 0.00005 seconds and 0.00050 seconds. |
| 32 | + |
| 33 | +| Day | Problem | Domain | Result | Time | Implementation | |
| 34 | +| :-: | :---------------------------------------------: | :-------------------------------------------------------------: | :-------------------: | :----: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 35 | +| 1 | [Trebuchet?!](src/day01b.c) | Strings, Tries | Sum | 0.0001 | Primitive [trie](https://en.wikipedia.org/wiki/Trie) | |
| 36 | +| 2 | [Cube Conundrum](src/day02b.c) | Strings | Sum | 0.0001 | | |
| 37 | +| 3 | [Gear Ratios](src/day03b.c) | Dynamic programming | Sum | 0.0001 | Sliding window technique | |
| 38 | +| 4 | [Scratchcards](src/day04b.c) | Sets | Sum | 0.0001 | | |
| 39 | +| 5 | [If You Give A Seed A Fertilizer](src/day05b.c) | Functions, Sorting algorithms | Minimum | 0.0001 | Function composition, System of linear equations | |
| 40 | +| 6 | [Wait For It](src/day06b.c) | Physics, Algebra | Product | 0.0001 | [Quadratic formula](https://en.wikipedia.org/wiki/Quadratic_formula) | |
| 41 | +| 7 | [Camel Cards](src/day07b.c) | Statistics, Dictionaries, Sorting algorithms | Sum | 0.0001 | Frequency map with mode-tracking | |
| 42 | +| 8 | [Haunted Wasteland](src/day08b.c) | Graph theory, Number theory, Dictionaries | Least Common Multiple | 0.0001 | [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm), map-based graph, base-36 encoding | |
| 43 | +| 9 | [Mirage Maintenance](src/day09b.c) | Numerical analysis | Sum | 0.0001 | [Lagrange polynomial](https://en.wikipedia.org/wiki/Lagrange_polynomial) | |
| 44 | +| 10 | [Pipe Maze](src/day10a.c) | Geometry, Graph theory, Pathfinding algorithms | Area | 0.0001 | [Flood-fill](https://en.wikipedia.org/wiki/Flood_fill), matrix-based graph | |
| 45 | +| 11 | [Cosmic Expansion](src/day11b.c) | Geometry | Sum | 0.0001 | [Taxicab geometry](https://en.wikipedia.org/wiki/Taxicab_geometry) | |
| 46 | +| 12 | [Hot Springs](src/day12b.c) | Automata theory, Regular expressions, Dictionaries | Sum | 0.01 | [Non-deterministic finite automaton](https://en.m.wikipedia.org/wiki/Nondeterministic_finite_automaton), iterable dictionary | |
| 47 | +| 13 | [Point of Incidence](src/day13b.c) | Binary arithmetic | Sum | 0.0001 | Bit array, bit matrix | |
| 48 | +| 14 | [Parabolic Reflector Dish](src/day14b.c) | Strings, Dictionaries | Sum | 0.0001 | Character matrix, cycle detection | |
| 49 | +| 15 | [Lens Library](src/day15b.c) | Cryptography, Hash functions, Dictionaries, Strings | Sum | 0.0001 | Iterable ordered dictionary, Length-prefixed string | |
| 50 | +| 16 | [The Floor Will Be Lava](src/day16b.c) | Stacks, Sets, Dictionaries | Maximum | 0.01 | Array stack, array set, array map, character matrix | |
| 51 | +| 17 | [Clumsy Crucible](src/day17b.c) | Graph theory, Pathfinding algorithms, Priority queues | Minimum | 0.01 | [Dijkstra\'s algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm), [circular buffer](https://en.wikipedia.org/wiki/Circular_buffer), state matrix | |
| 52 | +| 18 | [Lavaduct Lagoon](src/day18b.c) | Geometry | Area | 0.0001 | [Shoelace formula](https://en.wikipedia.org/wiki/Shoelace_formula), [Pick\'s theorem](https://en.wikipedia.org/wiki/Pick%27s_theorem) | |
| 53 | +| 19 | [Aplenty](src/day19b.c) | Parsing algorithms, Recursion, Stacks, Functions, Dictionaries | Count | 0.0001 | [Recursive descent parser](https://en.wikipedia.org/wiki/Recursive_descent_parser), dictionary | |
| 54 | +| 20 | [Pulse Propagation](src/day20b.c) | Graph theory, Number theory, Dictionaries, Sets, Circuit design | Product | 0.01 | [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm), map-based graph, hash set, length-prefixed string | |
| 55 | +| 21 | [Step Counter](src/day21a.c) | Graph theory, Sets, Priority queues | Count | 0.001 | [Breadth-first search](https://en.wikipedia.org/wiki/Breadth-first_search), hash set, [circular buffer](https://en.wikipedia.org/wiki/Circular_buffer), matrix-based graph | |
| 56 | +| 22 | [Sand Slabs](src/day22b.c) | Geometry, Graph theory, Sorting algorithms, Stacks, Sets | Count | 0.01 | Object-based graph, hash set | |
| 57 | +| 24 | [Never Tell Me The Odds](src/day24b.c) | Physics, Linear algebra | Sum | 0.01 | [Line–line intersection](https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection), [Gaussian elimination](https://en.wikipedia.org/wiki/Gaussian_elimination) | |
| 58 | +| 25 | [Snowverload](src/day25z.c) | Graph theory | Product | 0.001 | [Max-flow min-cut theorem](https://en.wikipedia.org/wiki/Max-flow_min-cut_theorem), [Ford–Fulkerson algorithm](https://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm), adjacency list, iterable graph | |
| 59 | + |
| 60 | +## Constraints |
| 61 | + |
| 62 | +I am working within the following constraints to ensure high code quality. |
| 63 | + |
| 64 | +- Adhere to the [project style guide](cstyle.md). |
| 65 | +- Final solutions must be implemented in the C programming language following |
| 66 | + the C99 standard. |
| 67 | + - Assume signed integer overflow is defined based on two\'s complement. |
| 68 | +- All solutions must be standalone files with no user-defined headers and no |
| 69 | + external dependencies beyond the C standard library (`libc`) and the C |
| 70 | + mathematics library (`libm`). The first and second problems for a given day |
| 71 | + must be implemented separately. |
| 72 | +- Bounds checking is not required for data structures whose capacity is defined |
| 73 | + by a macro. |
| 74 | +- The return values of all C standard library functions must be checked, except |
| 75 | + for those returned from the following: |
| 76 | + - `fprintf` |
| 77 | + - `memcpy` |
| 78 | + - `printf` |
| 79 | + |
| 80 | +## Omissions |
| 81 | + |
| 82 | +- The solution must produce the correct result for the [examples](data/), not |
| 83 | + just the personalized puzzle input. This means that the efficient solutions to |
| 84 | + Day 10(b) and Day 21(b) are unfeasible. I have omitted both. |
| 85 | +- By design, there is no efficient solution to Day 23(a) and (b). I have |
| 86 | + omitted both. |
0 commit comments