AoC2018/Day12/Part2.hs

31 lines
591 B
Haskell
Executable File

#! /usr/bin/env stack
-- stack --resolver lts-12.20 --install-ghc script
module Main where
-- After 101 generations a regular pattern emerges:
--
-- (101,3516)
-- (102,3541)
-- (103,3566)
-- (104,3591)
-- (105,3616)
-- (106,3641)
-- (107,3666)
-- (108,3691)
-- (109,3716)
-- (110,3741)
-- (111,3766)
-- (112,3791)
-- ...
main = print solution
where
n = 50000000000
solution = 3500
+ ((n - 101) `div` 4) * 100
+ (case n `mod` 4 of
1 -> 16
2 -> 41
3 -> 66
0 -> 91)