fun with cryptic oneliners

This commit is contained in:
Grimmauld 2024-12-05 17:32:08 +01:00
parent e1c70e7827
commit 85ecd2cfd0
Signed by: Grimmauld
SSH key fingerprint: SHA256:Q8IL6Y7sSKqzkyFdV1L0O/EflEh1fFV3tBtwxpapRH4
2 changed files with 2 additions and 0 deletions

View file

@ -13,4 +13,5 @@ in {
part1 = sumInBlock input;
part2 = listSum (map sumInBlock
(map (do: head (reSplit "don't\\(\\)" do)) (reSplit "do\\(\\)" input)));
part2oneline = foldl' add 0 (map (pipe' [ (matchAll "mul\\(([[:digit:]]{1,3}),([[:digit:]]{1,3})\\)") (foldl' (p: l: p + (head l |> toInt) * (last l |> toInt)) 0) ]) (map (pipe' [(reSplit "don't\\(\\)") head ]) (reSplit "do\\(\\)" (readFile ./input))));
}

View file

@ -17,4 +17,5 @@ with builtins; rec {
invert = f: x: !(f x);
elemAtMid = l: elemAt l ((length l) / 2);
removeAll = rl: (flip pipe) (map remove rl);
pipe' = flip pipe;
}