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
I’m an AWS Serverless Hero and the author of Production-Ready Serverless. I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless.
Here is a complete list of all my posts on serverless and AWS Lambda. In the meantime, here are a few of my most popular blog posts.
- Lambda optimization tip – enable HTTP keep-alive
- You are thinking about serverless costs all wrong
- Many faced threats to Serverless security
- We can do better than percentile latencies
- I’m afraid you’re thinking about AWS Lambda cold starts all wrong
- Yubl’s road to Serverless
- AWS Lambda – should you have few monolithic functions or many single-purposed functions?
- AWS Lambda – compare coldstart time with different languages, memory and code sizes
- Guys, we’re doing pagination wrong