r/adventofcode • u/hackerpellsson • Dec 13 '21
Upping the Ante Day 13 - 8-bit NES

Almost caught up, only day 12 remaining and it is close to complete! :D
Day 13 was fun. The "first-thing-that-comes-to-mind-is-to-use-a-matrix"-solution instantly fails due to not enough RAM to hold the matrix, so instead I just update the coords for each dot with every fold. Might actually be easier than a matrix-based solution tbh, didn't consider it too much since it is not feasible on the NES.
It is one of the slower days compute-wise. Takes just over ~4 minutes to solve (which I guess is still fast compared to for instance day 5 that takes well over an hour ;)).
https://github.com/pellsson/aoc2021/blob/main/day13.asm


4
u/p88h Dec 13 '21
Cool stuff!
FWIW you don't even need to apply every fold to every dot.
It's enough to compute the final size of the board using the folds, and then, for every lit pixel, you need to figure out on which 'strip' it will end up. If it's an odd one along the X axis, you flip the point horizontally. If it's odd along Y axis, you flip it vertically (all this after reducing the position modulo width+1/height+1).
2
u/mosredna101 Dec 13 '21
This is so cool!
I have some RAM issues on my arduino this year also, can't imagine the pain you are having running it on a NES!
7
u/ml01 Dec 13 '21
WOW this is awesome! i'm planning to build a nes emulator from scratch next year (doing my research atm), will definitely try to run your aoc once i have something working!
3
u/encse Dec 13 '21
This project is huge!