These are some Advent of Code solutions. They consist of two versions of each problem, the answer to the first unlocks the second (harder) version. For many of these I didn’t bother preserving the code for the first version.
The problems start in Ruby, then switch to Haskell, and then Rust. The problems get more interesting towards the end.
All of the entries below were solved for both parts of the challenge.
https://adventofcode.com/2020/day/2
Validate passwords.
Code.
Given the list of passwords and associated validation policies, count the number of valid passwords.
cd ./2020/2
ruby prt2.rb
total: 1000 valid: 745
https://adventofcode.com/2020/day/3
Assess different paths down a ski-free-style tree-filled ski slope.
Extending an initial ski slope to the right as needed, and looking at the following angles: Right 1, down 1. Right 3, down 1. Right 5, down 1. Right 7, down 1. Right 1, down 2. How many trees would be encountered along each angle and what is the product of them?
cd ./2020/3
ruby prt1.rb 2
hits per angle: [74, 189, 65, 63, 30]
product: 1718180100
https://adventofcode.com/2020/day/4
Validate passports given a specific list of rules.
How many passports are valid?
cd ./2020/4
ruby solve_2.rb
179
https://adventofcode.com/2020/day/5
Decode a list of boarding passes encoded in binary space partitioning.
Given all the boarding passes, Part one: What is the highest seat ID on a boarding pass? Part two: Which seat id is missing from the list?
cd ./2020/5
ruby solve.rb
Part one: higest seat id: 998
Part two: missing: 676
https://adventofcode.com/2020/day/6
Deciphering affirmative the answers on a customs declaration form for everyone on your plane.
Given the affirmative declaration list, Part one: For each group, count the number of questions to which anyone answered “yes”. What is the sum of those counts?
Part Two: For each group, count the number of questions to which everyone answered “yes”. What is the sum of those counts?
cd ./2020/6
ruby solve.rb
sum of disjunct counts: 6532
sum of conjunct counts: 3427
https://adventofcode.com/2020/day/7
Traverse the relationships between bags that can contain other bags.
Given the bag rules: Part one: How many bag colors can eventually contain at least one shiny gold bag? Part two: How many individual bags are required inside your single shiny gold bag?
cd ./2020/7
ruby solve.rb
Part one, possible containers: 259
part two, required contents: 45018
https://adventofcode.com/2020/day/8
Given assembly code with a fatal loop, first detect the loop, detect the broken instruction, fix the instruction and run the program.
After the (repaired) program terminates, what is the final accumulator?
cd ./2020/8
ruby solve.rb
{:accumulator=>1671, :pointer=>151, :state=>:loop}
https://adventofcode.com/2020/day/9
Find the weakness in a fake encryption scheme (eXchange-Masking Addition System (XMAS)).
What is the encryption weakness in your XMAS-encrypted list of numbers?
cd ./2020/9
ruby solve.rb
init: 70639851
sum: 7996275
https://adventofcode.com/2020/day/10
Determine combinations of valid chains of voltage adapters, given specific rules about how they can be linked.
Part one: Given your set of adapter “joltages”, find a chain that uses all of your adapters, and count the joltage differences between the charging outlet, the adapters, and your device. What is the number of 1-jolt differences multiplied by the number of 3-jolt differences?
Part two: What is the total number of distinct ways you can arrange the adapters to connect the charging outlet to your device?
cd ./2020/10
ruby solve.rb
Part one, 1 jolt by 3 jolts: 2112
Part two, total combos: 65792
https://adventofcode.com/2020/day/11
Given an initial seating chart, people occupy and leave seats based on the number of other occupied seats the occupant would see in eight directions.
Given the initial seating chart, cycle the seats until they reach an equilibrium. How many seats are occupied in the final state?
cd ./2020/haskell
cabal run --allow-newer=base eleven
Right 1937
https://adventofcode.com/2020/day/12
Follow instructions to navigate a ship through a 2D plane.
Given the input, what is the manhattan distance between the ship’s starting position and final position?
cd ./2020/haskell
cabal run --allow-newer=base twelve
Right 59435
https://adventofcode.com/2020/day/14
Processes instructions for writing to simulated memory addresses with bitmasks.
Given the input, what is the sum of all the values in memory after completing the instructions?
cd ./2020/haskell
cabal run --allow-newer=base fourteen
Right 4160009892257
https://adventofcode.com/2020/day/15
Generates numbers according to particular rules, and depending on previous numbers generated.
Given the input, which is just hardcoded in the executable, what is the 2020th number generated?
cd ./2020/haskell
cabal run --allow-newer=base fifteen
Right 59006
https://adventofcode.com/2020/day/17
A variation of game-of-life where the game has no border. It starts out with a set number of coordinates, but can exand infinitely as more coordinates become activated. The first part is three dimensional, and the second is four.
Part one code and tests. Part two code and tests.
After six cycles, how many active points exists? (The input is just hardcoded in the executable).
cd ./2020/17/seventeen
cargo run
3D: after 6 cycles, the count of active cubes is 315
4D: after 6 cycles, the count of active cubes is 1520