diff --git a/day01/Commons.hs b/day01/Commons.hs index ef80e4a..c15c805 100644 --- a/day01/Commons.hs +++ b/day01/Commons.hs @@ -16,4 +16,4 @@ parse = do done <- isEOF then return [] else do line <- parseLine doc <- parse - return (line:doc) + return $ line: doc diff --git a/day01/Main.hs b/day01/Main.hs index 3a15b8d..dedeb3d 100644 --- a/day01/Main.hs +++ b/day01/Main.hs @@ -6,7 +6,7 @@ import Part2 main = do doc <- parse - let part1Res = sum (Part1.getCalibrationValues doc) + let part1Res = sum $ Part1.getCalibrationValues doc print part1Res - let part2Res = sum (Part2.getCalibrationValues doc) + let part2Res = sum $ Part2.getCalibrationValues doc print part2Res diff --git a/day01/Part1.hs b/day01/Part1.hs index 3268c2c..ece54e1 100644 --- a/day01/Part1.hs +++ b/day01/Part1.hs @@ -9,7 +9,7 @@ getCalibrationValuePart (h: _) | isDigit h = h getCalibrationValuePart (_: t) = getCalibrationValuePart t getCalibrationValue :: CalibrationLine -> Integer -getCalibrationValue line = read [getCalibrationValuePart line, getCalibrationValuePart (reverse line)] +getCalibrationValue line = read [getCalibrationValuePart line, getCalibrationValuePart . reverse $ line] getCalibrationValues :: CalibrationDocument -> [Integer] getCalibrationValues [h] = [getCalibrationValue h] diff --git a/day01/Part2.hs b/day01/Part2.hs index 6fdb24b..52906e4 100644 --- a/day01/Part2.hs +++ b/day01/Part2.hs @@ -32,7 +32,7 @@ getCalibrationValueRight (h: _) | isDigit h = h getCalibrationValueRight (_: t) = getCalibrationValueRight t getCalibrationValue :: CalibrationLine -> Integer -getCalibrationValue line = read [getCalibrationValueLeft line, getCalibrationValueRight (reverse line)] +getCalibrationValue line = read [getCalibrationValueLeft line, getCalibrationValueRight . reverse $ line] getCalibrationValues :: CalibrationDocument -> [Integer] getCalibrationValues [h] = [getCalibrationValue h] diff --git a/day02/Commons.hs b/day02/Commons.hs index bd0664a..b922dcd 100644 --- a/day02/Commons.hs +++ b/day02/Commons.hs @@ -16,10 +16,10 @@ parseCubes ([h, "green"]: t) round = parseCubes t round {green = read h} parseCubes ([h, "blue"]: t) round = parseCubes t round {blue = read h} parseRound :: String -> Round -parseRound roundRaw = parseCubes (map words (split ", " roundRaw)) Round {red = 0, green = 0, blue = 0} +parseRound roundRaw = parseCubes (map words $ split ", " roundRaw) Round {red = 0, green = 0, blue = 0} parseRounds :: String -> [Round] -parseRounds roundsRaw = map parseRound (split "; " roundsRaw) +parseRounds roundsRaw = map parseRound $ split "; " roundsRaw parseGameId :: String -> String parseGameId ('G': 'a': 'm': 'e': ' ': t) = parseGameId t @@ -28,7 +28,7 @@ parseGameId [] = [] parseGame :: String -> Game parseGame line = let (h: t: _) = split ": " line - in Game {gid = read (parseGameId h), rounds = parseRounds t} + in Game {gid = read . parseGameId $ h, rounds = parseRounds t} parse :: IO [Game] parse = do done <- isEOF @@ -37,4 +37,4 @@ parse = do done <- isEOF else do line <- getLine let game = parseGame line otherGames <- parse - return (game: otherGames) + return $ game: otherGames diff --git a/day02/Main.hs b/day02/Main.hs index 9fc049e..057b24a 100644 --- a/day02/Main.hs +++ b/day02/Main.hs @@ -6,7 +6,7 @@ import Part2 main = do games <- parse - let part1Res = sum (Part1.getPossibleIds games) + let part1Res = sum $ Part1.getPossibleIds games print part1Res - let part2Res = sum (Part2.getPower games) + let part2Res = sum $ Part2.getPower games print part2Res diff --git a/day02/Part2.hs b/day02/Part2.hs index f050c03..4c3ce2f 100644 --- a/day02/Part2.hs +++ b/day02/Part2.hs @@ -1,13 +1,14 @@ module Part2 where import Commons +import Data.Function (on) getMinCubesRound :: [Round] -> Round getMinCubesRound [round] = round -getMinCubesRound (round: otherRound: t) = getMinCubesRound (Round {red = max (red round) (red otherRound), - green = max (green round) (green otherRound), - blue = max (blue round) (blue otherRound)}: t) +getMinCubesRound (round: otherRound: t) = getMinCubesRound $ Round {red = (max `on` red) round otherRound, + green = (max `on` green) round otherRound, + blue = (max `on` blue) round otherRound}: t getPowerGame :: Game -> Int getPowerGame Game{rounds=rounds} = let minRound = getMinCubesRound rounds diff --git a/day03/Commons.hs b/day03/Commons.hs index e2d01f5..80da8f3 100644 --- a/day03/Commons.hs +++ b/day03/Commons.hs @@ -37,7 +37,7 @@ parseNumberPart row column rawNumber = let value = parseNumberPartValue rawNumbe parseLine :: Int -> Int -> String -> Engine -> Engine parseLine _ _ [] engine = engine -parseLine row column (h: t) engine | isDigit h = let newNumberPart = parseNumberPart row column (h: t) +parseLine row column (h: t) engine | isDigit h = let newNumberPart = parseNumberPart row column $ h: t newNumberLength = numberLength newNumberPart in parseLine row (column + newNumberLength) (drop (newNumberLength - 1) t) @@ -56,7 +56,7 @@ parseEngine row engine = do done <- isEOF then return engine else do line <- getLine let newEngine = parseLine row 1 line engine - parseEngine (row+1) newEngine + parseEngine (row + 1) newEngine parse :: IO Engine parse = parseEngine 1 Engine {numbers = [], symbols = []} diff --git a/day03/Main.hs b/day03/Main.hs index b6cd750..efcec3e 100644 --- a/day03/Main.hs +++ b/day03/Main.hs @@ -6,7 +6,7 @@ import qualified Part2 main = do engine <- parse - let part1Res = sum (Part1.getActualPartValuesNumbersFromEngine engine) + let part1Res = sum $ Part1.getActualPartValuesNumbersFromEngine engine print part1Res - let part2Res = sum (Part2.getGearRatiosFromEngine engine) + let part2Res = sum $ Part2.getGearRatiosFromEngine engine print part2Res diff --git a/day03/Part1.hs b/day03/Part1.hs index 70f62b7..f912090 100644 --- a/day03/Part1.hs +++ b/day03/Part1.hs @@ -15,4 +15,4 @@ getActualPartNumbers (h: t) symbolsCoordinates getActualPartValuesNumbersFromEngine :: Engine -> [Int] getActualPartValuesNumbersFromEngine engine = - map value (getActualPartNumbers (numbers engine) (map coordinates (symbols engine))) + map value $ getActualPartNumbers (numbers engine) $ map coordinates $ symbols engine diff --git a/day03/Part2.hs b/day03/Part2.hs index 105ca3f..9fa9772 100644 --- a/day03/Part2.hs +++ b/day03/Part2.hs @@ -32,4 +32,4 @@ getGearRatios (h: t) numberParts = let gearRatio = getGearRatio h numberParts else getGearRatios t numberParts getGearRatiosFromEngine :: Engine -> [Int] -getGearRatiosFromEngine engine = getGearRatios (symbols engine) (numbers engine) +getGearRatiosFromEngine engine = getGearRatios (symbols engine) $ numbers engine diff --git a/day04/Commons.hs b/day04/Commons.hs index aa0ed49..8a47dc8 100644 --- a/day04/Commons.hs +++ b/day04/Commons.hs @@ -25,4 +25,4 @@ parse = do done <- isEOF else do line <- getLine let card = parseCard line otherCards <- parse - return (card: otherCards) + return $ card: otherCards diff --git a/day04/Main.hs b/day04/Main.hs index 1f2b8eb..1ac5ea3 100644 --- a/day04/Main.hs +++ b/day04/Main.hs @@ -6,7 +6,7 @@ import qualified Part2 main = do cards <- parse - let part1Res = sum (Part1.getAllPoints cards) + let part1Res = sum $ Part1.getAllPoints cards print part1Res - let part2Res = sum (Part2.getNCopies cards) + let part2Res = sum $ Part2.getNCopies cards print part2Res diff --git a/day04/Part1.hs b/day04/Part1.hs index f143c69..5343dc1 100644 --- a/day04/Part1.hs +++ b/day04/Part1.hs @@ -9,7 +9,7 @@ getNWinningNumbers winningNumbers (n: t) | n `elem` winningNumbers = 1 + getNWin | otherwise = getNWinningNumbers winningNumbers t getPoints :: Card -> Int -getPoints card = let nWinningNumbers = getNWinningNumbers (winningNumbers card) (numbers card) +getPoints card = let nWinningNumbers = getNWinningNumbers (winningNumbers card) $ numbers card in if nWinningNumbers == 0 then 0 else 2 ^ (nWinningNumbers - 1) diff --git a/day04/Part2.hs b/day04/Part2.hs index b940029..f4d989e 100644 --- a/day04/Part2.hs +++ b/day04/Part2.hs @@ -13,7 +13,7 @@ updateNCopies 0 card otherCards = otherCards updateNCopies n card (c: t) = c {nCopies = nCopies card + nCopies c}: updateNCopies (n - 1) card t updateCopies :: Card -> [Card] -> [Card] -updateCopies card otherCards = let nWinningNumbers = getNWinningNumbers (winningNumbers card) (numbers card) +updateCopies card otherCards = let nWinningNumbers = getNWinningNumbers (winningNumbers card) $ numbers card in updateNCopies nWinningNumbers card otherCards updateAllCopies :: [Card] -> [Card] @@ -21,4 +21,4 @@ updateAllCopies [] = [] updateAllCopies (c: t) = c: updateAllCopies (updateCopies c t) getNCopies :: [Card] -> [Int] -getNCopies cards = map nCopies (updateAllCopies cards) +getNCopies cards = map nCopies $ updateAllCopies cards