diff --git a/2/solution.nix b/2/solution.nix index 87a6c70..abfe080 100644 --- a/2/solution.nix +++ b/2/solution.nix @@ -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 = split (a: b: [(mvId "A" a) (mvId "X" b)] ); + convertMvId = splitPair (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 (split getScore) m); + totalScore = m: sum (map (splitPair 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 (split (a: b: [a (bestMove a b)] )); + makeBestMoves = map (splitPair (a: b: [a (bestMove a b)] )); in { part1 = totalScore matches; part2 = totalScore (makeBestMoves matches); diff --git a/4/solution.nix b/4/solution.nix index 620ecbf..b7ed2ba 100644 --- a/4/solution.nix +++ b/4/solution.nix @@ -4,10 +4,10 @@ let # read input input = readFile ./input; 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) ]; in map - (line: split readPair (splitString "," line)) + (line: splitPair readPair (splitString "," line)) (splitString "\n" input); # overlap functions @@ -20,7 +20,7 @@ let hasOverlap = overlapFunc: a: 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; - overlaps = overlapFunc: map boolToInt (map (split (hasOverlap overlapFunc)) pairs); + overlaps = overlapFunc: map boolToInt (map (splitPair (hasOverlap overlapFunc)) pairs); in { part1 = sum (overlaps completeOverlap); part2 = sum (overlaps partialOverlap); diff --git a/util.nix b/util.nix index f36209f..5f4683d 100644 --- a/util.nix +++ b/util.nix @@ -7,7 +7,7 @@ let # find the total sum of a int list sum = foldr (x: y: x + y) 0; # 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 maxList = foldr max 0; # Sorts a int list. Greatest value first