Advent of Code 2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
599 B

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