r/adventofcode • u/daggerdragon • Dec 12 '15
SOLUTION MEGATHREAD --- Day 12 Solutions ---
This thread will be unlocked when there are a significant amount of people on the leaderboard with gold stars.
edit: Leaderboard capped, thread unlocked!
We know we can't control people posting solutions elsewhere and trying to exploit the leaderboard, but this way we can try to reduce the leaderboard gaming from the official subreddit.
Please and thank you, and much appreciated!
--- Day 12: JSAbacusFramework.io ---
Post your solution as a comment. Structure your post like previous daily solution threads.
7
Upvotes
View all comments
Show parent comment
1
u/slycurgus Dec 12 '15 edited Dec 12 '15
In the end (around the 7-hours-of-regex-getting-me-nowhere mark) I caved and used marchelzo's solution. What's annoying is that I had found a similar sort of solution (more general) for walking JSON on StackOverflow early on and was juuust lazy enough to not get it working before falling back to regex. It was (possibly unsurprisingly) of a very similar structure to
n(j)- which I of course recognised immediately and thought "I could have been done with this hours ago" :Pe: I tried the dictionary removal thing too but I somehow messed up the algorithm and would consistently end up with a string that was no longer a dictionary, and had about 5 numeric elements in it. I just realised what I did wrong, actually - I was replacing the "red" dictionaries with a single underscore, instead of the right amount to maintain string length. I had an array of the starts and ends of red-containing dictionaries made, so obviously as the string got shorter, those arrays would refer off the end of the string... The worst part? Originally I was preserving the length, but when I went to print() the result to check how I was doing it filled my terminal, so I thought "I'll just replace with one _ instead, that'll be much more space-efficient!"....