Advent-of-Nix-2024/day1/default.nix

13 lines
362 B
Nix
Raw Normal View History

2024-12-01 15:50:11 +01:00
{ lib, utils, ... }:
with lib;
with builtins;
with utils;
let
numbers = map (l: map toInt (splitWhitespace l)) (readLines ./input);
left = sortOn noop (map (flip elemAt 0) numbers);
right = sortOn noop (map (flip elemAt 1) numbers);
in {
part1 = listSum (zipListsWith delta left right);
part2 = listSum (map (x: x * (count (y: x == y) right)) left);
}