16 lines
440 B
Nix
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)));
|
|
}
|