2024 day 12 part 1 in js
This commit is contained in:
parent
2db8edb087
commit
161b2a7e6f
5 changed files with 74 additions and 5 deletions
|
@ -3,6 +3,8 @@
|
|||
inherit (lib.strings) toIntBase10;
|
||||
in input: rec {
|
||||
|
||||
sum = foldl' add 0;
|
||||
|
||||
blinkStone = stone: count:
|
||||
if toIntBase10 stone == 0 then [{ "1" = count; }]
|
||||
else let
|
||||
|
@ -21,19 +23,17 @@ in input: rec {
|
|||
;
|
||||
|
||||
bfast = stones: stones
|
||||
|> (builtins.mapAttrs (stone: blinkStone stone))
|
||||
|> builtins.mapAttrs blinkStone
|
||||
|> attrValues
|
||||
|> concatLists
|
||||
|> addStones
|
||||
|> builtins.zipAttrsWith (stone: sum)
|
||||
;
|
||||
|
||||
bfastt = times: stones:
|
||||
if times == 0 then stones |> attrValues |> foldl' add 0
|
||||
if times == 0 then stones |> attrValues |> sum
|
||||
else bfastt (times - 1) (bfast stones)
|
||||
;
|
||||
|
||||
addStones = builtins.zipAttrsWith (stone: foldl' add 0);
|
||||
|
||||
initialStones = input
|
||||
|> lib.trim
|
||||
|> lib.splitString " "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue