This commit is contained in:
2025-12-01 14:38:16 +00:00
parent 27aad6b738
commit 064504ab2b
3 changed files with 3 additions and 78 deletions

View File

@@ -1,4 +1,4 @@
Part 1: Santa delivering over a grid of houses
Use realloc/malloc?
To me, this is kinda a memory management problem. Basically, we must create a 2D array of infinite size. Which we can't, as I don't have infinite memory (640K ought to be enough for anyone? Maybe I should see if I can compile this and run it on a virtual 8088). Fortunately, the file can be dealt with using fgetc, so I don't need to allocate that. So now I need to learn the allocation functions in C.
@@ -26,38 +26,6 @@ So, it seems that really what I'll be doing is managing arrays of pointers for r
I really like passing the pointer to the struct to the function in C, it makes things quite elegant (and easier for memory management!) as you're updating fields in a struct rather than creating a new copy each time. There's probably performance benefits, but this is so tiny that I'm unlikely to have to think about that. The new_grid pointers being inserted into the ->houses slot is handy. Did I say I really like only having one struct in play?
https://adventofcode.com/2015/day/3
--- Day 3: Perfectly Spherical Houses in a Vacuum ---
Santa is delivering presents to an infinite two-dimensional grid of houses.
He begins by delivering a present to the house at his starting location, and then an elf at the North Pole calls him via radio and tells him where to move next. Moves are always exactly one house to the north (^), south (v), east (>), or west (<). After each move, he delivers another present to the house at his new location.
However, the elf back at the north pole has had a little too much eggnog, and so his directions are a little off, and Santa ends up visiting some houses more than once. How many houses receive at least one present?
For example:
> delivers presents to 2 houses: one at the starting location, and one to the east.
^>v< delivers presents to 4 houses in a square, including twice to the house at his starting/ending location.
^v^v^v^v^v delivers a bunch of presents to some very lucky children at only 2 houses.
Your puzzle answer was 2565.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
The next year, to speed up the process, Santa creates a robot version of himself, Robo-Santa, to deliver presents with him.
Santa and Robo-Santa start at the same location (delivering two presents to the same starting house), then take turns moving based on instructions from the elf, who is eggnoggedly reading from the same script as the previous year.
This year, how many houses receive at least one present?
For example:
^v delivers presents to 3 houses, because Santa goes north, and then Robo-Santa goes south.
^>v< now delivers presents to 3 houses, and Santa and Robo-Santa end up back where they started.
^v^v^v^v^v now delivers presents to 11 houses, with Santa going one direction and Robo-Santa going the other.
PART 2 COMMENTS