Cleanup functions
This commit is contained in:
parent
13f84a3296
commit
fb7913ad3d
@ -6,7 +6,7 @@ let
|
||||
totalsPerElf = map sum elfCalories;
|
||||
|
||||
part1 = maxList totalsPerElf;
|
||||
part2 = sum (topOfList (sortList totalsPerElf) 3);
|
||||
part2 = sum (topOfList 3 (sortList totalsPerElf));
|
||||
in {
|
||||
inherit part1;
|
||||
inherit part2;
|
||||
|
8
util.nix
8
util.nix
@ -6,15 +6,15 @@ let
|
||||
# Passthrough trace for debugging
|
||||
pTrace = v: lib.traceSeq v v;
|
||||
# find the total sum of a int list
|
||||
sum = l: lib.foldr (x: y: x + y) 0 l;
|
||||
sum = lib.foldr (x: y: x + y) 0;
|
||||
# splits a list of length two into two params then they're passed to a func
|
||||
split = pair: f: f (lib.head pair) (lib.last pair);
|
||||
# Finds the max value in a list
|
||||
maxList = l: lib.foldr lib.max 0 l;
|
||||
maxList = lib.foldr lib.max 0;
|
||||
# Sorts a int list. Greatest value first
|
||||
sortList = l: lib.sort (x: y: x > y) l;
|
||||
sortList = lib.sort (x: y: x > y);
|
||||
# Returns the top cnt items of the list
|
||||
topOfList = l: cnt: lib.take cnt l;
|
||||
topOfList = cnt: lib.take cnt;
|
||||
# Cuts a list in half and returns the two parts in a list
|
||||
cutInHalf = l: [(lib.take (lib.length l / 2) l) (lib.drop (lib.length l / 2) l)];
|
||||
# Splits a list into a list of lists with length cnt
|
||||
|
Loading…
x
Reference in New Issue
Block a user