by Martin KavalarMay 09 2019
Making science reproducible @nextjournal

# Rule 30

This is my implementation of Rule 30.

(def rule30
{"111" 0
"110" 0
"101" 0
"100" 1
"011" 1
"010" 1
"001" 1
"000" 0})
user/rule30
(get rule30 "010")
1
(def first-generation
(let [n 33
zeros (vec (replicate n 0))]
(assoc zeros (/ (dec n) 2) 1)))
user/first-generation
first-generation
Vector(33) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 13 more...]
(require '[clojure.string :as str])
(into []
(map (comp rule30 str/join))
(partition 3 1 (into [0 0] first-generation)))
Vector(33) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 13 more...]
(defn evolve [generation]
(into []
(map (comp rule30 str/join))
(partition 3 1 [0] (into [0] generation))))
user/evolve
(loop [generation first-generation]
(println (str/join generation))
(when (zero? (first generation))
(recur (evolve generation))))
(loop [generation first-generation]
(println (str/join (map #(if (zero? %) "." "■") generation)))
(when (zero? (first generation))
(recur (evolve generation))))