From 85ecd2cfd0d74c14bc17d586d4813e60378e0422 Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Thu, 5 Dec 2024 17:32:08 +0100 Subject: [PATCH] fun with cryptic oneliners --- day3/default.nix | 1 + utils.nix | 1 + 2 files changed, 2 insertions(+) diff --git a/day3/default.nix b/day3/default.nix index c913900..5cdb511 100644 --- a/day3/default.nix +++ b/day3/default.nix @@ -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)))); } diff --git a/utils.nix b/utils.nix index 81b61e4..a413ee3 100644 --- a/utils.nix +++ b/utils.nix @@ -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; }