You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/games/game_of_life.ark
+17-25Lines changed: 17 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -16,41 +16,33 @@
16
16
(let neigh (fun (board_ index) {
17
17
(let x (math:floor (mod index width)))
18
18
(let y (math:floor (/ index width)))
19
-
(+
20
-
(get board_ (- x 1) y)
21
-
(get board_ (+ x 1) y)
22
-
(get board_ x (- y 1))
23
-
(get board_ x (+ y 1))
24
-
(get board_ (- x 1) (- y 1))
25
-
(get board_ (+ x 1) (- y 1))
26
-
(get board_ (- x 1) (+ y 1))
27
-
(get board_ (+ x 1) (+ y 1))) }))
19
+
(+ (get board_ (- x 1) y) (get board_ (+ x 1) y) (get board_ x (- y 1)) (get board_ x (+ y 1)) (get board_ (- x 1) (- y 1)) (get board_ (+ x 1) (- y 1)) (get board_ (- x 1) (+ y 1)) (get board_ (+ x 1) (+ y 1))) }))
28
20
29
21
(let indices (list:iota 0 (* height width)))
30
22
(let update (fun (board) {
31
23
(mut copy (list:fill (* height width) dead))
32
24
33
-
(list:forEach indices
25
+
(list:forEach
26
+
indices
34
27
(fun (i) {
35
28
(let neighs (neigh board i))
36
-
(switch neighs
37
-
2 (@= copy i (@ board i))
38
-
3 (@= copy i alive)
39
-
_ (@= copy i dead)) }))
29
+
(switch neighs 2 (@= copy i (@ board i)) 3 (@= copy i alive) _ (@= copy i dead)) }))
0 commit comments