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

13 lines
361 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);
2024-12-01 15:59:47 +01:00
left = sort lessThan (map (flip elemAt 0) numbers);
right = sort lessThan (map (flip elemAt 1) numbers);
2024-12-01 15:50:11 +01:00
in {
part1 = listSum (zipListsWith delta left right);
2024-12-01 15:59:47 +01:00
part2 = listSum (map (x: x * (count (eq x) right)) left);
2024-12-01 15:50:11 +01:00
}