Something went wrong. Try again.
advent of code solutions op.tngl.io
Something went wrong. Try again.
12345678910111213141516171819202122{-# LANGUAGE LambdaCase #-}
import Data.List.Split (splitOn)import qualified Data.Map as Mimport Data.Maybe (fromMaybe)import System.Environment (getArgs)
grow m = M.insertWith (+) 6 new . M.insertWith (+) 8 new . M.mapKeys pred . M.delete 0 $ m where new = fromMaybe 0 $ M.lookup 0 m
main = do n <- fmap (map read . splitOn ",") $ getArgs >>= \case ["-"] -> getContents [file] -> readFile file let fish = M.fromListWith (+) $ map (,1) n print $ sum $ iterate grow fish !! 80 print $ sum $ iterate grow fish !! 256