mirror of
https://github.com/janet-lang/janet
synced 2025-02-17 17:20:01 +00:00
Update game of life example.
This commit is contained in:
parent
6d5ff43de7
commit
33087fe9de
@ -4,11 +4,11 @@
|
|||||||
(seq [x :range [-1 2]
|
(seq [x :range [-1 2]
|
||||||
y :range [-1 2]
|
y :range [-1 2]
|
||||||
:when (not (and (zero? x) (zero? y)))]
|
:when (not (and (zero? x) (zero? y)))]
|
||||||
(tuple x y)))
|
[x y]))
|
||||||
|
|
||||||
(defn- neighbors
|
(defn- neighbors
|
||||||
[[x y]]
|
[[x y]]
|
||||||
(map (fn [[x1 y1]] (tuple (+ x x1) (+ y y1))) window))
|
(map (fn [[x1 y1]] [(+ x x1) (+ y y1)]) window))
|
||||||
|
|
||||||
(defn tick
|
(defn tick
|
||||||
"Get the next state in the Game Of Life."
|
"Get the next state in the Game Of Life."
|
||||||
@ -28,7 +28,7 @@
|
|||||||
(loop [x :range [x1 (+ 1 x2)]
|
(loop [x :range [x1 (+ 1 x2)]
|
||||||
:after (print)
|
:after (print)
|
||||||
y :range [y1 (+ 1 y2)]]
|
y :range [y1 (+ 1 y2)]]
|
||||||
(file/write stdout (if (get cellset (tuple x y)) "X " ". ")))
|
(file/write stdout (if (get cellset [x y]) "X " ". ")))
|
||||||
(print))
|
(print))
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user