Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
Merge pull request #4 from theanalyst/hyisms
Browse files Browse the repository at this point in the history
Update conway to follow the newer hy syntax
  • Loading branch information
berkerpeksag committed Dec 31, 2013
2 parents 49cbdee + 667b99d commit 88c3c06
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions conway.hy
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

(def *world* (grid.Torus 10 10))

(defun set! (world x y value)
(defn set! [world x y value]
(setv (get world (, x y)) value))

(defun get! (world x y)
(defn get! [world x y]
(get *world* (, x y)))


(defun neighbours (world x y)
(defn neighbours [world x y]
(sum (list-comp
(get! world (+ x dx) (+ y dy))
(dx [-1 0 1]
dy [-1 0 1])
(!= (, (+ x dx) (+ y dy)) (, x y)))))

(defun step (world)
(let ((new-world (.copy grid.Torus world)))
(for (x (range new-world.width))
(for (y (range new-world.height))
(let ((cell (get! new-world x y))
(ns (neighbours world x y)))
(defn step [world]
(let [[new-world (.copy grid.Torus world)]]
(for [x (range new-world.width)]
(for [y (range new-world.height)]
(let [[cell (get! new-world x y)]
[ns (neighbours world x y)]]
(if (= cell 1)
(cond [(< ns 2) (set! new-world x y 0)]
[(or (= ns 2) (= ns 3)) (set! new-world x y 1)]
Expand All @@ -40,7 +40,7 @@
(set! *world* 5 4 1)

;; Cycle through once...
(for (_ (range 5))
(for [_ (range 5)]
(.pprint grid.Torus *world*)
(setv *world* (step *world*))
(print))

0 comments on commit 88c3c06

Please sign in to comment.