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

Updates to newer syntax #3

Merged
merged 1 commit into from
Oct 16, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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