Advent-of-Nix-2024/day3/default.nix
2024-12-03 10:51:06 +01:00

16 lines
440 B
Nix

{ lib, utils, ... }:
with lib;
with builtins;
with utils;
let
input = readFile ./input;
getFactorsInBlock = s:
map (map toInt)
(matchAll "mul\\(([[:digit:]]{1,3}),([[:digit:]]{1,3})\\)" s);
sumInBlock = block:
listSum (map (l: (head l) * (last l)) (getFactorsInBlock block));
in {
part1 = sumInBlock input;
part2 = listSum (map sumInBlock
(map (do: head (reSplit "don't\\(\\)" do)) (reSplit "do\\(\\)" input)));
}