-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day18.hs
54 lines (48 loc) · 913 Bytes
/
Day18.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Day18
( part1
, part2
) where
import Data.Text as T (Text, init, unpack)
expand :: [Bool] -> [Bool]
expand line = gol (False : line)
gol :: [Bool] -> [Bool]
gol [x, y] = [x]
gol (x:xs@(y:z:_)) =
((x && not y && not z)
|| (x && y && not z)
|| (not x && y && z)
|| (not x && not y && z))
: gol xs
render :: [[Bool]] -> String
render =
unlines
. map
(map
(\x ->
if x
then '^'
else '.'))
part1 :: Bool -> Text -> String
part1 test =
show
. sum
. map (length . filter not)
. take n
. iterate expand
. map (== '^')
. unpack
. T.init
where
n
| test = 10
| otherwise = 40
part2 :: Bool -> Text -> String
part2 _ =
show
. sum
. map (length . filter not)
. take 400000
. iterate expand
. map (== '^')
. unpack
. T.init