Skip to content

Commit c24c8f2

Browse files
committed
chore: format game_of_life.ark
1 parent b5ecac5 commit c24c8f2

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

examples/games/game_of_life.ark

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,33 @@
1616
(let neigh (fun (board_ index) {
1717
(let x (math:floor (mod index width)))
1818
(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))) }))
2820

2921
(let indices (list:iota 0 (* height width)))
3022
(let update (fun (board) {
3123
(mut copy (list:fill (* height width) dead))
3224

33-
(list:forEach indices
25+
(list:forEach
26+
indices
3427
(fun (i) {
3528
(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)) }))
4030

4131
copy }))
4232

43-
(let display (fun (board width height)
44-
(print (string:join
45-
(list:map
46-
(list:chunkBy
47-
(list:map board
48-
(fun (cell)
49-
(if (= alive cell) "x" "•")))
50-
3)
51-
(fun (sublist)
52-
(string:join sublist "")))
53-
"\n"))))
33+
(let display (fun (board width height) (print
34+
(string:join
35+
(list:map
36+
(list:chunkBy
37+
(list:map
38+
board
39+
(fun (cell)
40+
(if (= alive cell)
41+
"x"
42+
"•")))
43+
3)
44+
(fun (sublist) (string:join sublist "")))
45+
"\n"))))
5446

5547
(print "initial board:")
5648
(display board width height)

0 commit comments

Comments
 (0)