advent_of_code_2022

My (attempted) solutions to the 2022 Advent of Code
git clone https://git.eamoncaddigan.net/advent_of_code_2022.git
Log | Files | Refs | README

commit cf1d38d09caf7e3ba5a892b66df4de627607fd0a
parent d192fc570215a53f691896191f9bb005c9119134
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date:   Sun,  4 Dec 2022 04:26:07 -0800

Solution to day 3, part 2.

Diffstat:
Msrc/day_3.jl | 15++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/day_3.jl b/src/day_3.jl @@ -35,7 +35,20 @@ end @assert part_1(example) == 157 @info part_1(input) +# For part 2, we don't need to worry about rucksack compartments at all, but I +# already wrote the logic to turn items into values, and reusing +# get_compartments gave me the opportunity to learn about Julia's splat +# operator `...`. + +# This function takes a group of rucksacks (in string format) and finds the +# value of the "badge" +function get_rucksacks_badge(rucksacks) + intersect(map(x->union(x...), map(get_compartments, rucksacks))...)[1] +end + function part_2(input) - nothing + sum([get_rucksacks_badge(input[i:i+2]) + for i = 1:3:length(input)]) end +@assert part_2(example) == 70 @info part_2(input)