Advent of Code 2024, day 1, part 2
-- Problem: https://adventofcode.com/2024/day/1 (part two)
-- Run from the crate root: lbd run examples/aoc-24/day-01/part_02.lbd
use "../../std.lbd"
parseLine : String -> List<Number> = \line. (map parseNumber (split " " line))
columns : List<List<Number>> =
(transpose (map parseLine (lines (readFile "examples/aoc-24/day-01/input.txt"))))
left : List<Number> = (get 0 columns)
right : List<Number> = (get 1 columns)
similarity : Number = (sum (map \x. (mul x (count (eq x) right)) left))
(println "Answer: " similarity)
Output
Answer: 21070419
Run it yourself from the repository root: lbd run examples/aoc-24/day-01/part_02.lbd