2022-12-01 17:36:50 +01:00
|
|
|
{ lib ? import <nixpkgs/lib> }:
|
2022-12-01 17:24:54 +01:00
|
|
|
|
2022-12-01 17:36:50 +01:00
|
|
|
let
|
|
|
|
chomp = lib.removeSuffix "\n";
|
|
|
|
lines = s: builtins.filter builtins.isString (builtins.split "\n" (chomp s));
|
|
|
|
sum = builtins.foldl' builtins.add 0;
|
|
|
|
|
|
|
|
day01 =
|
|
|
|
let
|
|
|
|
input =
|
|
|
|
builtins.map
|
|
|
|
(elf:
|
|
|
|
sum (builtins.map builtins.fromJSON (lines elf))
|
|
|
|
)
|
|
|
|
(
|
|
|
|
builtins.filter builtins.isString (
|
|
|
|
builtins.split "\n\n" (builtins.readFile ./01/input)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
in
|
|
|
|
{
|
|
|
|
"1" = builtins.foldl' lib.max (-1) input;
|
|
|
|
"2" = sum (lib.sublist 0 3 (lib.sort (a: b: a >= b) input));
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
inherit day01;
|
|
|
|
}
|