20 lines
593 B
Nix
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;
|
|
}
|