Improve split
This commit is contained in:
parent
3a324d81a1
commit
4b08e2b19b
@ -8,7 +8,7 @@ let
|
||||
# convert moves to numbers for opponent and player
|
||||
# Rock -> 0, Paper -> 1, Scissors 2
|
||||
mvId = c: m: (charToInt m) - (charToInt c);
|
||||
convertMvId = pair: split pair (a: b: [(mvId "A" a) (mvId "X" b)] );
|
||||
convertMvId = split (a: b: [(mvId "A" a) (mvId "X" b)] );
|
||||
|
||||
# scoring matches
|
||||
isWin = a: b: (mod (a+1) 3) == b;
|
||||
@ -18,7 +18,7 @@ let
|
||||
(if isWin a b then 6
|
||||
else if isTie a b then 3
|
||||
else 0); # loss
|
||||
totalScore = m: sum (map (pair: split pair getScore) m);
|
||||
totalScore = m: sum (map (split getScore) m);
|
||||
|
||||
# part 2
|
||||
mkDraw = a: a;
|
||||
@ -28,7 +28,7 @@ let
|
||||
if b == 0 then mkLoss a
|
||||
else if b == 1 then mkDraw a
|
||||
else mkWin a;
|
||||
makeBestMoves = map (pair: split pair (a: b: [a (bestMove a b)] ));
|
||||
makeBestMoves = map (split (a: b: [a (bestMove a b)] ));
|
||||
in {
|
||||
part1 = totalScore matches;
|
||||
part2 = totalScore (makeBestMoves matches);
|
||||
|
Loading…
x
Reference in New Issue
Block a user