r/adventofcode • u/daggerdragon • Dec 23 '22
SOLUTION MEGATHREAD -π- 2022 Day 23 Solutions -π-
All of our rules, FAQs, resources, etc. are in our community wiki.
UPDATES
[Update @ 00:21:46]: SILVER CAP, GOLD 68
Stardew Valley ain't got nothing on these speedy farmer Elves!
AoC Community Fun 2022:
πΏπ MisTILtoe Elf-ucation π§βπ«
Submissions are CLOSED!
Thank you to all who submitted something!
Every last one of you are awesome!
Community voting is OPEN!
42 hours remaining until voting deadline on December 24 at 18:00 EST
Voting details are in the stickied comment at the top of the -βοΈ- Submissions Megathread -βοΈ-
--- Day 23: Unstable Diffusion ---
Post your code solution in this megathread.
Read the full posting rules in our community wiki before you post!
Include what language(s) your solution uses
Format code blocks using the four-spaces Markdown syntax!
Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
7
u/Colin-McMillen Dec 23 '22 edited Dec 23 '22
C on the Apple //c
Today memory is constrained a bit, with 2458 elves represented in a 8 bytes structure (x, y, planned_x, planned_y). The map size means I won't be able to use a tri-dimensional array to store which elves want to go to a given spot even if I complicate things to squeeze the elf struct.
The plan phase of rounds is OK, there's room enough for a bitfield representing the map so choosing where to go is about O(n).
But I had to keep a very naive algorithm iterating over all elves to see if any of them wants to go to the same spot during execution phase of a round, giving us a nice O(nΒ²) algorithm there.
Each round takes about 30 minutes so I guess I'll cancel after round 10 or this'll be about 19 days runtime.
Update: figured out I don't have to know all the elves who want to go to a single spot, just if there's more than one. I apparently should have just enough ram for a (width+2)*(height+2)*sizeof(short) to store that information at round plan time, and check it's still the same at execution time. Brought down each round to about one minute :)
Here's the code: https://github.com/colinleroy/aoc2022/blob/master/a2tools/src/aoc/day23/day23.c