Commit 79c9326d by Stuart Kurtz

Day 6, minor cleanups

parent 735cbe2f
Showing with 8 additions and 12 deletions
{-# LANGUAGE TypeApplications #-}
module Main where
import Data.Array
import Data.Array ( Array, array, (!), accumArray )
type Population = Array Int Int
......@@ -13,9 +11,9 @@ step a = array (0,8) [(x,f x) | x <- [0..8]] where
f n = a ! (n+1)
makeFish :: [Int] -> Array Int Int
makeFish = accumArray (+) 0 (0,8) . map (\x -> (x,1))
makeFish = accumArray (+) 0 (0,8) . map (flip (,) 1)
main :: IO ()
main = do
phases <- makeFish . read @[Int] . ("["++) . (++"]") <$> readFile "data/lantern-fish.txt"
phases <- makeFish . read . ("["++) . (++"]") <$> readFile "data/lantern-fish.txt"
print . sum $ iterate step phases !! 80
{-# LANGUAGE TypeApplications #-}
module Main where
import Data.Array
import Data.Array ( Array, array, (!), accumArray )
type Population = Array Int Int
......@@ -13,9 +11,9 @@ step a = array (0,8) [(x,f x) | x <- [0..8]] where
f n = a ! (n+1)
makeFish :: [Int] -> Array Int Int
makeFish = accumArray (+) 0 (0,8) . map (\x -> (x,1))
makeFish = accumArray (+) 0 (0,8) . map (flip (,) 1)
main :: IO ()
main = do
phases <- makeFish . read @[Int] . ("["++) . (++"]") <$> readFile "data/lantern-fish.txt"
phases <- makeFish . read . ("["++) . (++"]") <$> 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