19 lines
530 B
Haskell
19 lines
530 B
Haskell
wordsWhen :: (a -> Bool) -> [a] -> [[a]]
|
|
wordsWhen pred s =
|
|
case dropWhile pred s of
|
|
[] -> []
|
|
s' -> w : wordsWhen pred s''
|
|
where (w, s'') = break pred s'
|
|
|
|
parseFish :: String -> [Int]
|
|
parseFish = map read . wordsWhen (==',')
|
|
|
|
simulate :: Int -> [Int] -> Int
|
|
simulate 0 fish = length fish
|
|
simulate days fish =
|
|
simulate (days-1) $ concatMap (\f -> if f == 0
|
|
then [6,8]
|
|
else [f-1]) fish
|
|
|
|
main = interact $ show . simulate 80 . parseFish
|