aoc2021/Day6.hs

23 lines
599 B
Haskell

module Day6 where
import System.IO (openFile, IOMode (ReadMode), hClose, hGetContents)
import Data.Text (splitOn, unpack, pack)
import Prelude hiding (splitAt)
splitAt :: String -> String -> [String]
splitAt delimiter str = map unpack $ splitOn (pack delimiter) $ pack str
grow :: Int -> [Int]
grow f
| f > 0 = [f - 1]
| otherwise = [6, 8]
main :: IO ()
main = do
input <- openFile "inputs/6.txt" ReadMode
contents <- hGetContents input
let fishies = map read $ splitAt "," contents :: [Int]
print . length . (!! 80) $ iterate (concatMap grow) fishies
hClose input