Commit 735cbe2f by Stuart Kurtz

Day 6

parent 621efba9
......@@ -61,10 +61,12 @@ executable aoc-05b
executable aoc-06a
import : aoc-common
main-is : AOC-06a.hs
build-depends : array
executable aoc-06b
import : aoc-common
main-is : AOC-06b.hs
build-depends : array
executable aoc-07a
import : aoc-common
......
3,4,1,2,1,2,5,1,2,1,5,4,3,2,5,1,5,1,2,2,2,3,4,5,2,5,1,3,3,1,3,4,1,5,3,2,2,1,3,2,5,1,1,4,1,4,5,1,3,1,1,5,3,1,1,4,2,2,5,1,5,5,1,5,4,1,5,3,5,1,1,4,1,2,2,1,1,1,4,2,1,3,1,1,4,5,1,1,1,1,1,5,1,1,4,1,1,1,1,2,1,4,2,1,2,4,1,3,1,2,3,2,4,1,1,5,1,1,1,2,5,5,1,1,4,1,2,2,3,5,1,4,5,4,1,3,1,4,1,4,3,2,4,3,2,4,5,1,4,5,2,1,1,1,1,1,3,1,5,1,3,1,1,2,1,4,1,3,1,5,2,4,2,1,1,1,2,1,1,4,1,1,1,1,1,5,4,1,3,3,5,3,2,5,5,2,1,5,2,4,4,1,5,2,3,1,5,3,4,1,5,1,5,3,1,1,1,4,4,5,1,1,1,3,1,4,5,1,2,3,1,3,2,3,1,3,5,4,3,1,3,4,3,1,2,1,1,3,1,1,3,1,1,4,1,2,1,2,5,1,1,3,5,3,3,3,1,1,1,1,1,5,3,3,1,1,3,4,1,1,4,1,1,2,4,4,1,1,3,1,3,2,2,1,2,5,3,3,1,1
\ No newline at end of file
{-# LANGUAGE TypeApplications #-}
module Main where
import Data.Array
type Population = Array Int Int
step :: Population -> Population
step a = array (0,8) [(x,f x) | x <- [0..8]] where
f 8 = a ! 0
f 6 = a ! 7 + a ! 0
f n = a ! (n+1)
makeFish :: [Int] -> Array Int Int
makeFish = accumArray (+) 0 (0,8) . map (\x -> (x,1))
main :: IO ()
main = pure ()
main = do
phases <- makeFish . read @[Int] . ("["++) . (++"]") <$> readFile "data/lantern-fish.txt"
print . sum $ iterate step phases !! 80
{-# LANGUAGE TypeApplications #-}
module Main where
import Data.Array
type Population = Array Int Int
step :: Population -> Population
step a = array (0,8) [(x,f x) | x <- [0..8]] where
f 8 = a ! 0
f 6 = a ! 7 + a ! 0
f n = a ! (n+1)
makeFish :: [Int] -> Array Int Int
makeFish = accumArray (+) 0 (0,8) . map (\x -> (x,1))
main :: IO ()
main = pure ()
main = do
phases <- makeFish . read @[Int] . ("["++) . (++"]") <$> readFile "data/lantern-fish.txt"
print . sum $ iterate step phases !! 256
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment