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

Commit

Permalink
Updates to newer syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe H. Rahme committed Oct 16, 2013
1 parent 7aa6072 commit 4d08783
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions conway.hy
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
(import grid)
(import-from functools reduce)
(import-from operator add)


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


(defun sum (ns)
(reduce add ns))


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


(defun get! (world x y)
(get *world* (, x y)))

Expand All @@ -25,19 +16,18 @@
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)))
(if (= cell 1)
(cond ((< ns 2) (set! new-world x y 0))
((or (= ns 2) (= ns 3)) (set! new-world x y 1))
((> ns 3) (set! new-world x y 0)))
(cond ((= ns 3) (set! new-world x y 1))
(True (set! new-world x y 0)))))))
(cond [(< ns 2) (set! new-world x y 0)]
[(or (= ns 2) (= ns 3)) (set! new-world x y 1)]
[(> ns 3) (set! new-world x y 0)])
(cond [(= ns 3) (set! new-world x y 1)]
[True (set! new-world x y 0)])))))
new-world))


Expand Down

0 comments on commit 4d08783

Please sign in to comment.