blob: ca8bfc6e57df2403258e22c6905cded1cc91b31b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
{ lib ? import <nixpkgs/lib> }:
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;
}
|