Last active
June 2, 2025 14:18
-
-
Save turanct/d376e9dbe8d48732ab94 to your computer and use it in GitHub Desktop.
Revisions
-
turanct revised this gist
Nov 9, 2015 . 1 changed file with 11 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,15 +32,16 @@ (define neighbours (lambda (coord) (let ((x (get-x coord)) (y (get-y coord))) (list (create-coord x (+ y 1)) (create-coord x (- y 1)) (create-coord (+ x 1) y) (create-coord (- x 1) y) (create-coord (+ x 1) (+ y 1)) (create-coord (- x 1) (- y 1)) (create-coord (+ x 1) (- y 1)) (create-coord (- x 1) (+ y 1)))))) (define neighbours-in-generation (lambda (cell generation) @@ -94,4 +95,4 @@ (display generation) (newline) (sleep 2) (game (next-generation generation))))))) -
turanct revised this gist
Jun 6, 2015 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,9 +34,13 @@ (lambda (coord) (list (create-coord (get-x coord) (+ (get-y coord) 1)) (create-coord (get-x coord) (- (get-y coord) 1)) (create-coord (+ (get-x coord) 1) (get-y coord)) (create-coord (- (get-x coord) 1) (get-y coord)) (create-coord (+ (get-x coord) 1) (+ (get-y coord) 1)) (create-coord (- (get-x coord) 1) (- (get-y coord) 1)) (create-coord (+ (get-x coord) 1) (- (get-y coord) 1)) (create-coord (- (get-x coord) 1) (+ (get-y coord) 1))))) (define neighbours-in-generation (lambda (cell generation) -
turanct created this gist
Jun 6, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,93 @@ (define create-coord (lambda (x y) (list x y))) (define get-x (lambda (coord) (car coord))) (define get-y (lambda (coord) (car (cdr coord)))) (define equal-coords? (lambda (c1 c2) (and (= (get-x c1) (get-x c2)) (= (get-y c1) (get-y c2))))) (define coord-in-list-of-coords? (lambda (coord list-of-coords) (cond ((null? list-of-coords) #f) ((equal-coords? coord (car list-of-coords)) #t) (else (coord-in-list-of-coords? coord (cdr list-of-coords)))))) (define no-duplicate-coords (lambda (list-of-coords) (cond ((null? list-of-coords) (list)) ((coord-in-list-of-coords? (car list-of-coords) (cdr list-of-coords)) (no-duplicate-coords (cdr list-of-coords))) (else (cons (car list-of-coords) (no-duplicate-coords (cdr list-of-coords))))))) (define neighbours (lambda (coord) (list (create-coord (get-x coord) (+ (get-y coord) 1)) (create-coord (- (get-x coord) 1) (get-y coord)) (create-coord (+ (get-x coord) 1) (get-y coord)) (create-coord (get-x coord) (- (get-y coord) 1))))) (define neighbours-in-generation (lambda (cell generation) (filter (lambda (neighbour) (coord-in-list-of-coords? neighbour generation)) (neighbours cell)))) (define cell-lives-on (lambda (cell generation) (let ((neighbours (neighbours-in-generation cell generation))) (or (= (length neighbours) 2) (= (length neighbours) 3))))) (define cell-is-born (lambda (coord generation) (let ((neighbours (neighbours-in-generation coord generation))) (= (length neighbours) 3)))) (define consider-newborn-cells (lambda (generation) (cond ((null? generation) (list)) (else (filter (lambda (coord) (not (coord-in-list-of-coords? coord generation))) (no-duplicate-coords (append (neighbours (car generation)) (consider-newborn-cells (cdr generation))))))))) (define next-generation (lambda (generation) (append (filter (lambda (cell) (cell-lives-on cell generation)) generation) (filter (lambda (coord) (cell-is-born coord generation)) (consider-newborn-cells generation))))) (define game (lambda (generation) (cond ((null? generation) (begin (display "done") (newline))) (else (begin (display generation) (newline) (sleep 2) (game (next-generation generation)))))))