I was certain that C would really help me with the bit fiddly puzzles, but yesterday kicked my booty and left me slapping together something ugly but functional in Python. I switched over after encountering a realloc bug in my custom hashmap implementation. So. I've got some more studying to do on that front. Hopefully you had a better day.
The Puzzle
In today’s puzzle, we're hanging out with the elves! They're playing a number game that involves remembering the last time a particular number was said and generating an infinite sequence from that. I'm thinking that there may be some tricks learned from past years that may be applicable here, but I'll confirm once I've gone through it and submitted my solution. Good luck!
The Leaderboards
As always, this is the spot where I’ll plug any leaderboard codes shared from the community.
Ryan's Leaderboard: 224198-25048a19
If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.
Yesterday’s Languages
Updated 07:36AM 12/15/2020 PST.
Language | Count |
---|---|
Rust | 2 |
Haskell | 2 |
JavaScript | 2 |
COBOL | 1 |
Merry Coding!
Top comments (12)
I did a basic dynamic programming solution
Didn't really find this one interesting. Apparently it's a known series.
Either way, Ruby it was:
Here's part 1 JS, part 2 is a big performance issue. EDIT: I tried using
new Map()
for a more efficient process but I still ran into the call stack size error. I guess Javascript and heavy processing don't fit together :(You can use a map to store the numbers you've seen. Map lookup is O(1), compared to looking through a list (O(n)). The keys can be the numbers you've seen, the values the list of positions.
Thank you for the suggestion! I'll try it!
Technically simple but designed to catch out the users of, ahem, more academic languages! Rust should offer good performance of course. Optimised build runs both parts in about 5 seconds.
Ruby solution. Same thing for Part 1 and 2.
My Haskell solution for today was quite short, but performance was shit.
It's in Python, and it's not pretty, but I'm busy and it works and keeps me on track, so I'm counting that as a win. Just got to get through this week of finals and then I'll have more time :) Part two takes a while, but not like a "get up and get some coffee" while, so I'll take it.
COBOL as usual
Here is my Haskell solution, please don't ask about performance for that big number :-)
My JavaScript walkthrough:
Video: