advent_of_code/2025/utils.nix
RingOfStorms (Joshua Bell) 6a41f0587c day 2 part 1
2025-12-08 22:32:17 -06:00

20 lines
593 B
Nix

with builtins;
rec {
toIntBase10 = str: fromJSON "${str}";
mod = a: b: a - b * (floor (a / b));
min = a: b: if a < b then a else b;
max = a: b: if a > b then a else b;
split = delim: input: filter (s: isString s && s != "") (split delim input);
reduce = foldl'; # foldl' (acc: elem: acc + elem) 0 [1 2 3]
flatten = input: concatMap (x: if isList x then x else [ x ]) input;
rangeInclusive =
min: max:
if min > max then
[ ]
else
let
len = max - min + 1;
in
genList (i: min + i) len;
sum = input: reduce (sum: v: sum + v) 0 input;
}