cleanup
This commit is contained in:
parent
4f3ad6d920
commit
9790098496
2 changed files with 4 additions and 4 deletions
|
@ -4,9 +4,9 @@ with builtins;
|
||||||
with utils;
|
with utils;
|
||||||
let
|
let
|
||||||
numbers = map (l: map toInt (splitWhitespace l)) (readLines ./input);
|
numbers = map (l: map toInt (splitWhitespace l)) (readLines ./input);
|
||||||
left = sortOn noop (map (flip elemAt 0) numbers);
|
left = sort lessThan (map (flip elemAt 0) numbers);
|
||||||
right = sortOn noop (map (flip elemAt 1) numbers);
|
right = sort lessThan (map (flip elemAt 1) numbers);
|
||||||
in {
|
in {
|
||||||
part1 = listSum (zipListsWith delta left right);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,6 @@ with builtins; rec {
|
||||||
splitWhitespace = s: filter isString (builtins.split "[[:space:]]+" s);
|
splitWhitespace = s: filter isString (builtins.split "[[:space:]]+" s);
|
||||||
abs = i: if i >= 0 then i else i * -1;
|
abs = i: if i >= 0 then i else i * -1;
|
||||||
delta = x: y: abs (x - y);
|
delta = x: y: abs (x - y);
|
||||||
noop = x: x;
|
|
||||||
listSum = foldl' add 0;
|
listSum = foldl' add 0;
|
||||||
|
eq = x: y: x == y;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue