Lambda Discipline

Examples

Advent of Code 2024, day 1, part 1

examples/aoc-24/day-01/part_01.lbd

-- Problem: https://adventofcode.com/2024/day/1 (part one)
-- Run from the crate root: lbd run examples/aoc-24/day-01/part_01.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> = (sort (get 0 columns))
right : List<Number> = (sort (get 1 columns))

distance : Number = (sum (zipWith \a. \b. (abs (sub a b)) left right))

(println "Answer: " distance)

Output

Answer: 1223326

Run it yourself from the repository root: lbd run examples/aoc-24/day-01/part_01.lbd