Day 2: Corruption Checksum

Having split, max, min and sum0 in the language really simplifies the code. But it was still fun and would make a nice exercise in any programming course. Still perl of course. It'll take another day to switch.

Day 3: Spiral Memory

This is the first one I actually spent some time thinking about. I tried (and failed) to find the clever math solution. Only later after I looked at the solutions megathread I realized how close I was and what needed to be done.

In any case after failing to find the clever solution I went with a brute force ruby code. This was my longest (and ugliest) solution of the week:

In part 1 I wrote a Counter class that calculates (x,y) coordinates for each step. Later in part 2 it was easy to add a Board class that remembers which squares were calculated and calculates the next by summing all the neighbors.

I later thought I could use that Board approach from the beginning to calculate the next square's coordinates. For example when moving right one could look "up" and continue moving right until you find a free square above. I never did that refactoring though because new days brought new quizzes.

Day 4 - High-Entropy Passphrases

Day 4 is when I realized if I want to learn something from this game I better pick a new language. Level was back to fizz-buzz style games so it shouldn't be too hard. I picked Elixir and from here all my solutions are written in it (hope I'll be able to continue this till the end of the month).

I used a MapSet to find duplicates and checked each line's unique word count to see if it's a valid passphrase. I learned to use String.split with trim to remove blanks. I also learned elixir's way to read from stdin.

Day 5: A Maze of Twisty Trampolines

In day 5 I learned about elixir's strange performance issue: Being an immutable language means it has no efficient way to mutate a vector.

Following some advice in elixir subreddit I eventually learned to use a hash map with increasing numbers as keys (and values are the things in the "vector") to emulate a vector. This has allowed running part 2 in 12 seconds (instead of 40 using tuples).

In this quiz I also started to use Stream.unfold to create custom streams. This turned out to be a good patterns because it allows one to decouple the quiz logic from the actual question.

Note the second part (the "main" of the program). Having the game logic implemented as streams makes it trivial to run the streams until we reach a certain point, and then continue from that same point to count something else. The second loop takes as its starting condition the last element from the first loop.

All in all it was a fun week. I learned a lot about Elixir. I plan to continue with Elixir hoping to gain a better understanding of the language.