diff --git a/day1/default.nix b/day1/default.nix index f87383e..6e69d0f 100644 --- a/day1/default.nix +++ b/day1/default.nix @@ -4,9 +4,9 @@ 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); + left = sort lessThan (map (flip elemAt 0) numbers); + right = sort lessThan (map (flip elemAt 1) numbers); in { part1 = listSum (zipListsWith delta left right); - part2 = listSum (map (x: x * (count (y: x == y) right)) left); + part2 = listSum (map (x: x * (count (eq x) right)) left); } diff --git a/utils.nix b/utils.nix index 0dae919..bcc7e79 100644 --- a/utils.nix +++ b/utils.nix @@ -5,6 +5,6 @@ with builtins; rec { splitWhitespace = s: filter isString (builtins.split "[[:space:]]+" s); abs = i: if i >= 0 then i else i * -1; delta = x: y: abs (x - y); - noop = x: x; listSum = foldl' add 0; + eq = x: y: x == y; }