ps. look out for all my other solutions for Advent of Code challenges here.
See details of the challenge here.
The input for today’s challenge looks something like this:
So our first task is to turn these into a more usable format, eg. a tuple of (encrypted name, sector ID, checksum).
To find the real room names, we need to calculate the checksum value from the encrypted name.
To produce the desired sorting in LINQ, I’d have used OrderByDescending and ThenBy. There is no ThenBy in any of the F# modules, but F# tuples are ordered the way you expect – by first item, then second item, and so on.
So, I can achieve the same result as OrderByDescending + ThenBy with one line instead:
Seq.sortBy (fun (c, cs) -> –(Seq.length cs), c)
pretty neat, right?
With all the decoy data out of the way, it’s time to decrypt this list and get
The room names are encrypted by a state-of-the-art shift cipher, which is nearly
unbreakable without the right software. However, the information kiosk designers
at Easter Bunny HQ were not expecting to deal with a master cryptographer like
To decrypt a room name, rotate each letter forward through the alphabet a number
of times equal to the room’s sector ID. A becomes B, B becomes C, Z becomes A,
and so on. Dashes become spaces.
For example, the real name for qzmt-zixmtkozy-ivhz-343 is very encrypted name.
What is the sector ID of the room where North Pole objects are stored?
First, let’s add a decrypt function:
I found the question “where North Pole objects are stored” ambigious. After a few failed attempts to guess what the room name should be I ended up just printing them all out and did a quick search for “north“. I’m not sure if the author of the challenge expected you to do that, or maybe I missed a clue somewhere..
Anyhow, once I figured out what the room name is, getting the sector ID was easy.
- Day 4 challenge description
- Advent of Code 2015
- Solution for Day 3
- All my F# solutions for Advent of Code
- Github repo