slight cleanup
This commit is contained in:
parent
9653f71512
commit
4a4041a8bd
|
@ -2,12 +2,7 @@ module Main where
|
|||
|
||||
import Data.List
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
raw <- getLine
|
||||
let input = (toSchool . collect . sort) $ map read $ words $ map (\c -> if c == ',' then ' ' else c) raw
|
||||
putStrLn $ "day6a: " ++ (show $ sumSchool ((iterate transform input) !! 80))
|
||||
putStrLn $ "day6b: " ++ (show $ sumSchool ((iterate transform input) !! 256))
|
||||
-- this is a little gross
|
||||
|
||||
data School = School
|
||||
{ day0 :: Integer
|
||||
|
@ -21,6 +16,29 @@ data School = School
|
|||
, day8 :: Integer
|
||||
} deriving Show
|
||||
|
||||
toSchool' :: [(Integer,Integer)] -> School -> School
|
||||
toSchool' [] s = s
|
||||
toSchool' ((i,n):is) s
|
||||
| i == 0 = toSchool' is $ s { day0 = n }
|
||||
| i == 1 = toSchool' is $ s { day1 = n }
|
||||
| i == 2 = toSchool' is $ s { day2 = n }
|
||||
| i == 3 = toSchool' is $ s { day3 = n }
|
||||
| i == 4 = toSchool' is $ s { day4 = n }
|
||||
| i == 5 = toSchool' is $ s { day5 = n }
|
||||
| i == 6 = toSchool' is $ s { day6 = n }
|
||||
| i == 7 = toSchool' is $ s { day7 = n }
|
||||
| i == 8 = toSchool' is $ s { day8 = n }
|
||||
| otherwise = error "index too large"
|
||||
|
||||
-- sorry i couldnt be bothered learning haskell arrays
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
raw <- getLine
|
||||
let input = (toSchool . collect . sort) $ map read $ words $ map (\c -> if c == ',' then ' ' else c) raw
|
||||
putStrLn $ "day6a: " ++ (show $ sumSchool ((iterate transform input) !! 80))
|
||||
putStrLn $ "day6b: " ++ (show $ sumSchool ((iterate transform input) !! 256))
|
||||
|
||||
sumSchool :: School -> Integer
|
||||
sumSchool (School a b c d e f g h i) =
|
||||
a + b + c + d + e + f + g + h + i
|
||||
|
@ -36,19 +54,5 @@ collect is = map f $ group is
|
|||
then error "empty list"
|
||||
else ((head js), toInteger (length js))
|
||||
|
||||
toSchool' :: [(Integer,Integer)] -> School -> School
|
||||
toSchool' [] s = s
|
||||
toSchool' ((i,n):is) s
|
||||
| i == 0 = toSchool' is $ s { day0 = n }
|
||||
| i == 1 = toSchool' is $ s { day1 = n }
|
||||
| i == 2 = toSchool' is $ s { day2 = n }
|
||||
| i == 3 = toSchool' is $ s { day3 = n }
|
||||
| i == 4 = toSchool' is $ s { day4 = n }
|
||||
| i == 5 = toSchool' is $ s { day5 = n }
|
||||
| i == 6 = toSchool' is $ s { day6 = n }
|
||||
| i == 7 = toSchool' is $ s { day7 = n }
|
||||
| i == 8 = toSchool' is $ s { day8 = n }
|
||||
| otherwise = error "index too large"
|
||||
|
||||
toSchool :: [(Integer,Integer)] -> School
|
||||
toSchool is = toSchool' is (School 0 0 0 0 0 0 0 0 0)
|
||||
|
|
Loading…
Reference in a new issue