DEV Community

Discussion on: Advent of Code 2020 - Day 23

Collapse
 
neilgall profile image
Neil Gall • Edited

I really like your analysis and break down to a very simple representation so it works even in Python. Linked lists are the way to go. Circular ones even better. I've been doing AoC in Rust this year but resorted to C for part 2 today. Runs in under a second. github.com/neilgall/advent-of-code...

There are a few tricks in here from my old embedded C days. I allocate all the objects in one big contiguous buffer then set up the links between them using a pointer-to-pointer to track the previous link in the chain. Changing the order is only ever a few pointer moves.

For fun I did it again in unsafe Rust, but to be honest the C version looks nicer! github.com/neilgall/advent-of-code...

Collapse
 
matju profile image
matju

Yeah - linked lists with pointers are notoriously hard in Rust! As it's just using an array of numbers, I think the Python solution above is pretty much line-by-line translatable to a safe Rust solution though.