2016-12-04 Advent of Code in Java

I use Java to earn money, even though I don’t really like working with it. Everything is so damn verbose. If you return to writing Java code within Emacs you’ll realize that a big chunk of the code you’re writing gets written by the IDE, e.g. imports. Static typing and object orientation has resulted in basically every object defining a separate interface which you need to memorize. It’s hard to write code without completion. Anyway, I decided to solve today’s Advent of Code riddles using Java.

Advent of Code

First question. Your input is a list of strings. Each string has the form NAME-ID[CHECKSUM]. NAME consists of lowercase letters separated by dashes, ID is a number and CHECKSUM are the five most common letters in NAME, sorted by frequency with ties broken by alphabetical sorting. What is the sum of all the IDs where the CHECKSUM is correct?

This checksum is valid, for example and thus the sum would be 123:

The enjoyable part about this exercise was that I got to use Java 8 streams. Yay me!

Second question. For every string with correct CHECKSUM, rotate the letters in NAME by the ID. The example given shows how the letter `q` in a NAME with ID 343 would end up a `v`. To find the actual answer asked for in the question, grep the result for a line containing “north”.

​#Java ​#Advent of Code ​#Programming