use Integer -> String -> String for solve
This commit is contained in:
parent
8eb1e52c83
commit
ea99a0f4b8
5 changed files with 17 additions and 16 deletions
|
@ -21,5 +21,5 @@ main = do
|
||||||
4 -> Aoc.Day4.solve
|
4 -> Aoc.Day4.solve
|
||||||
_ -> error "unknown day"
|
_ -> error "unknown day"
|
||||||
|
|
||||||
putStrLn $ show $ f part contents
|
putStrLn $ f part contents
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ part2 = sum . take 3 . sortDesc . inputSums
|
||||||
where
|
where
|
||||||
sortDesc = sortBy (comparing Down)
|
sortDesc = sortBy (comparing Down)
|
||||||
|
|
||||||
solve :: Integer -> String -> Integer
|
solve :: Integer -> String -> String
|
||||||
solve 1 input = part1 input
|
solve 1 input = show $ part1 input
|
||||||
solve 2 input = part2 input
|
solve 2 input = show $ part2 input
|
||||||
|
solve _ _ = "?"
|
||||||
|
|
|
@ -19,8 +19,8 @@ scoreGame _ = 0
|
||||||
totalScore :: [[String]] -> Integer
|
totalScore :: [[String]] -> Integer
|
||||||
totalScore = sum . map scoreGame
|
totalScore = sum . map scoreGame
|
||||||
|
|
||||||
solve :: Integer -> String -> Integer
|
solve :: Integer -> String -> String
|
||||||
solve 1 input = totalScore games
|
solve 1 input = show $ totalScore games
|
||||||
where
|
where
|
||||||
games = map convertGuide $ parseInput input
|
games = map convertGuide $ parseInput input
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ solve 1 input = totalScore games
|
||||||
convertGuide [p, "Z"] = [p, "C"]
|
convertGuide [p, "Z"] = [p, "C"]
|
||||||
convertGuide xs = xs
|
convertGuide xs = xs
|
||||||
|
|
||||||
solve 2 input = totalScore games
|
solve 2 input = show $ totalScore games
|
||||||
where
|
where
|
||||||
games = map solveGuide $ parseInput input
|
games = map solveGuide $ parseInput input
|
||||||
|
|
||||||
|
@ -45,4 +45,4 @@ solve 2 input = totalScore games
|
||||||
solveGuide ["C", "Z"] = ["C", "A"]
|
solveGuide ["C", "Z"] = ["C", "A"]
|
||||||
solveGuide xs = xs
|
solveGuide xs = xs
|
||||||
|
|
||||||
solve _ _ = 0
|
solve _ _ = "?"
|
||||||
|
|
|
@ -21,9 +21,9 @@ charToInt c
|
||||||
| 'A' <= c && c <= 'Z' = ord c - ord 'A' + 27
|
| 'A' <= c && c <= 'Z' = ord c - ord 'A' + 27
|
||||||
| otherwise = -1
|
| otherwise = -1
|
||||||
|
|
||||||
solve :: Integer -> String -> Integer
|
solve :: Integer -> String -> String
|
||||||
solve 1 input = sum $ map (toInteger . charToInt . head . shared . halve) $ lines input
|
solve 1 input = show $ sum $ map (toInteger . charToInt . head . shared . halve) $ lines input
|
||||||
|
|
||||||
solve 2 input = sum $ map (toInteger . charToInt . head . shared) $ chunksOf 3 $ lines input
|
solve 2 input = show $ sum $ map (toInteger . charToInt . head . shared) $ chunksOf 3 $ lines input
|
||||||
|
|
||||||
solve _ _ = 0
|
solve _ _ = "?"
|
||||||
|
|
|
@ -45,8 +45,8 @@ overlap ((a, b), (c, d))
|
||||||
solve' :: String -> (Row -> Bool) -> Integer
|
solve' :: String -> (Row -> Bool) -> Integer
|
||||||
solve' input predicate = fromIntegral $ length $ filter predicate $ parse input
|
solve' input predicate = fromIntegral $ length $ filter predicate $ parse input
|
||||||
|
|
||||||
solve :: Integer -> String -> Integer
|
solve :: Integer -> String -> String
|
||||||
solve 1 input = solve' input fullOverlap
|
solve 1 input = show $ solve' input fullOverlap
|
||||||
solve 2 input = solve' input overlap
|
solve 2 input = show $ solve' input overlap
|
||||||
|
|
||||||
solve _ _ = 0
|
solve _ _ = "?"
|
||||||
|
|
Loading…
Reference in a new issue