Rename split to splitPair
This commit is contained in:
parent
79244532fb
commit
8cb3c32aa5
@ -8,7 +8,7 @@ let
|
|||||||
# convert moves to numbers for opponent and player
|
# convert moves to numbers for opponent and player
|
||||||
# Rock -> 0, Paper -> 1, Scissors 2
|
# Rock -> 0, Paper -> 1, Scissors 2
|
||||||
mvId = c: m: (charToInt m) - (charToInt c);
|
mvId = c: m: (charToInt m) - (charToInt c);
|
||||||
convertMvId = split (a: b: [(mvId "A" a) (mvId "X" b)] );
|
convertMvId = splitPair (a: b: [(mvId "A" a) (mvId "X" b)] );
|
||||||
|
|
||||||
# scoring matches
|
# scoring matches
|
||||||
isWin = a: b: (mod (a+1) 3) == b;
|
isWin = a: b: (mod (a+1) 3) == b;
|
||||||
@ -18,7 +18,7 @@ let
|
|||||||
(if isWin a b then 6
|
(if isWin a b then 6
|
||||||
else if isTie a b then 3
|
else if isTie a b then 3
|
||||||
else 0); # loss
|
else 0); # loss
|
||||||
totalScore = m: sum (map (split getScore) m);
|
totalScore = m: sum (map (splitPair getScore) m);
|
||||||
|
|
||||||
# part 2
|
# part 2
|
||||||
mkDraw = a: a;
|
mkDraw = a: a;
|
||||||
@ -28,7 +28,7 @@ let
|
|||||||
if b == 0 then mkLoss a
|
if b == 0 then mkLoss a
|
||||||
else if b == 1 then mkDraw a
|
else if b == 1 then mkDraw a
|
||||||
else mkWin a;
|
else mkWin a;
|
||||||
makeBestMoves = map (split (a: b: [a (bestMove a b)] ));
|
makeBestMoves = map (splitPair (a: b: [a (bestMove a b)] ));
|
||||||
in {
|
in {
|
||||||
part1 = totalScore matches;
|
part1 = totalScore matches;
|
||||||
part2 = totalScore (makeBestMoves matches);
|
part2 = totalScore (makeBestMoves matches);
|
||||||
|
@ -4,10 +4,10 @@ let
|
|||||||
# read input
|
# read input
|
||||||
input = readFile ./input;
|
input = readFile ./input;
|
||||||
pairs = let
|
pairs = let
|
||||||
readRange = s: split (a: b: [ (toInt a) (toInt b) ]) (splitString "-" s);
|
readRange = s: splitPair (a: b: [ (toInt a) (toInt b) ]) (splitString "-" s);
|
||||||
readPair = a: b: [ (readRange a) (readRange b) ];
|
readPair = a: b: [ (readRange a) (readRange b) ];
|
||||||
in map
|
in map
|
||||||
(line: split readPair (splitString "," line))
|
(line: splitPair readPair (splitString "," line))
|
||||||
(splitString "\n" input);
|
(splitString "\n" input);
|
||||||
|
|
||||||
# overlap functions
|
# overlap functions
|
||||||
@ -20,7 +20,7 @@ let
|
|||||||
hasOverlap = overlapFunc: a: b:
|
hasOverlap = overlapFunc: a: b:
|
||||||
let a1 = head a; b1 = head b; a2 = last a; b2 = last b;
|
let a1 = head a; b1 = head b; a2 = last a; b2 = last b;
|
||||||
in overlapFunc a1 a2 b1 b2 || overlapFunc b1 b2 a1 a2;
|
in overlapFunc a1 a2 b1 b2 || overlapFunc b1 b2 a1 a2;
|
||||||
overlaps = overlapFunc: map boolToInt (map (split (hasOverlap overlapFunc)) pairs);
|
overlaps = overlapFunc: map boolToInt (map (splitPair (hasOverlap overlapFunc)) pairs);
|
||||||
in {
|
in {
|
||||||
part1 = sum (overlaps completeOverlap);
|
part1 = sum (overlaps completeOverlap);
|
||||||
part2 = sum (overlaps partialOverlap);
|
part2 = sum (overlaps partialOverlap);
|
||||||
|
2
util.nix
2
util.nix
@ -7,7 +7,7 @@ let
|
|||||||
# find the total sum of a int list
|
# find the total sum of a int list
|
||||||
sum = foldr (x: y: x + y) 0;
|
sum = foldr (x: y: x + y) 0;
|
||||||
# splits a list of length two into two params then they're passed to a func
|
# splits a list of length two into two params then they're passed to a func
|
||||||
split = f: pair: f (head pair) (last pair);
|
splitPair = f: pair: f (head pair) (last pair);
|
||||||
# Finds the max value in a list
|
# Finds the max value in a list
|
||||||
maxList = foldr max 0;
|
maxList = foldr max 0;
|
||||||
# Sorts a int list. Greatest value first
|
# Sorts a int list. Greatest value first
|
||||||
|
Loading…
x
Reference in New Issue
Block a user