|
I've been solving these with Haskell. Mostly it's been going well, but my Day 6 solution was very inefficient because I implemented it with the Data.Array module and couldn't figure out how to only run through the indices that were actually changed with the available functions, so I ended up updating the entire array every time. I probably should've used a mutable 2D array of some sort instead, but my initial solution was barely fast enough to be acceptable so I didn't bother. Day 7 tripped me up repeatedly because I didn't understand the question correctly: - At first I thought a wire would always already have a signal at the time it's used to provide a signal for another wire, mostly because that was the case in the example. Actually looking at the input cleared up that misconception. - Then I for some reason got it into my head that if a wire doesn't have a signal when it's used it should be treated as having the value 0. I pulled this out of thin air, and it was obviously wrong. - At last I realized that you're supposed to go through the list repeatedly until all the signals are turned on (or build some sort of expression tree by going backwards, I guess), so I changed up my algorithm and got a plausible result, but it was still wrong. - Then I spent another half hour or so until I finally realized I had been rotating the bits instead of shifting them. I found Day 8 to be simpler in comparison. I used the very awesome Parsec library to parse the strings and got the right result pretty quickly. Using regex or even just simple string matching would probably be just as easy, but they're not as cool as Parsec.
|
# ¿ Dec 8, 2015 16:38 |
|
|
# ¿ May 13, 2024 04:11 |
|
I like how you're giving us all these NP-complete problems but making the datasets juuust small enough that you can brute force them.
|
# ¿ Dec 15, 2015 12:34 |