6.12
Advent of Code: solutions & explanations
Dedicated to curious characters everywhere, especially those learning Racket.
Advent of Code is a series of programming puzzles designed by Eric Wastl.
I find that programming puzzles are a good way of learning something new about a programming language, or learning how to do certain things better. Documenting these solutions helped me nail down some discoveries.
Thank you to Eric Wastl. If you like Advent of Code, please pay him for it.
You can install this package (if you haven’t already) with
raco pkg install aocracket
1 Day 1 
1.1 Where does the elevator land? 
1.1.1 Alternate approach: numerical conversion 
1.2 At what point does the elevator enter the basement? 
1.2.1 Alternate approaches: for/first or for/or 
1.3 Testing Day 1 

2 Day 2 
2.1 How much paper is needed to wrap the boxes? 
2.2 How much ribbon is needed to wrap the boxes? 
2.3 Testing Day 2 

3 Day 3 
3.1 How many grid cells are visited? 
3.1.1 Alternate approach: complex numbers 
3.2 How many grid cells are visited if the path is split? 
3.3 Testing Day 3 

4 Day 4 
4.1 What is the lowestnumbered MD5 hash starting with five zeroes? 
4.2 How about six zeroes? 
4.3 Testing Day 4 

5 Day 5 
5.1 How many strings are “nice”? 
5.2 How many strings are “nice” under new rules? 
5.3 Testing Day 5 

6 Day 6 
6.1 How many lights are lit after following the instructions? 
6.2 What is the total brightness of the lights if the rules are reinterpreted? 
6.3 Refactored solution 
6.4 Testing Day 6 

7 Day 7 
7.1 What’s the signal on wire a? 
7.2 What’s the signal on wire a if wire b is overridden with a’s original value? 
7.3 Testing Day 7 

8 Day 8 
8.1 What’s the difference between the literal length of the strings, and their length in memory? 
8.2 What’s the difference between the reencoded length of the literal string, and the original length? 
8.3 Testing Day 8 

9 Day 9 
9.1 What’s the shortest route that visits all the cities? 
9.2 What’s the longest route? 
9.3 Testing Day 9 

10 Day 10 
10.1 What’s the length of the sequence after 40 iterations? 
10.2 After 50 iterations? 
10.3 Testing Day 10 

11 Day 11 
11.1 What’s the next password that meets the criteria? 
11.2 What’s the next valid password after that? 
11.3 Testing Day 11 

12 Day 12 
12.1 What’s the sum of all the numbers in the document? 
12.2 What’s the sum of all the numbers, if hash tables with value "red" are ignored? 
12.3 Testing Day 12 

13 Day 13 
13.1 What’s the optimal happiness score for a seating arrangement of eight? 
13.1.1 Optimizing inpermutations 
13.2 What’s the optimal happiness score, including ourself in the seating? 
13.3 Testing Day 13 

14 Day 14 
14.1 After 2503 seconds, what is the maximum distance any reindeer has flown? 
14.2 Under the new rule, how many points does the winning reindeer have? 
14.3 Testing Day 14 

15 Day 15 
15.1 What’s the best cookie we can make with 100 tsps of ingredients? 
15.2 What’s the best cookie we can make with 100 tsps that’s exactly 500 calories? 
15.3 Testing Day 15 

16 Day 16 
16.1 Which Sue matches the attribute input? 
16.2 Which Sue matches the attribute input, with the “retroencabulator” rules? 
16.3 Testing Day 16 

17 Day 17 
17.1 How many combinations of containers fit exactly 150 liters? 
17.2 How many combinations have the minimum number of containers? 
17.3 Testing Day 17 

18 Day 18 
18.1 How many lights are on after 100 iterations of the lightswitching rules? 
18.2 How many lights are on after 100 iterations, if the corner bulbs are always lit? 
18.3 Testing Day 18 

19 Day 19 
19.1 How many distinct molecules can be created after one transformation? 
19.2 What’s the fewest number of transformations that will generate the test module? 
19.3 Testing Day 19 

20 Day 20 
20.1 What’s the first house that gets the target number of presents? 
20.2 What’s the first house that gets the target number of presents, if each elf delivers 11 gifts to 50 houses? 
20.3 Testing Day 20 

21 Day 21 
21.1 What’s the least we can spend and win? 
21.2 What’s the most we can spend and lose? 
21.3 Testing Day 21 

22 Day 22 
22.1 You’re a Wizard, Henry 
22.2 What’s the least (mana) we can spend and win? 
22.3 Hard Mode 
22.4 Testing Day 22 

23 Day 23 
23.1 What’s the value in register b after the program runs? 
23.2 What’s the value in register b if register a starts as 1? 
23.3 Testing Day 23 

24 Day 24 
24.1 What’s the score of the optimal group of packages, when divided into three groups? 
24.2 What’s the optimal score when divided into four groups? 
24.3 Testing Day 24 

25 Day 25 
25.1 What code do you give the machine? 
25.2 Testing Day 25 

Index 