March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env lein-exec
|
||||
|
||||
(require '[clojure.string :as str])
|
||||
|
||||
(def first-genr "_###_##_#_#_#_#__#__")
|
||||
|
||||
(def hospitable #{"_##"
|
||||
"##_"
|
||||
"#_#"})
|
||||
|
||||
(defn compute-next-genr
|
||||
[genr]
|
||||
(let [genr (str "_" genr "_")
|
||||
groups (map str/join (partition 3 1 genr))
|
||||
next-genr (for [g groups]
|
||||
(if (hospitable g) \# \_))]
|
||||
(str/join next-genr)))
|
||||
|
||||
;; ---------------- main -----------------
|
||||
(loop [g first-genr
|
||||
i 0]
|
||||
(if (not= i 10)
|
||||
(do (println g)
|
||||
(recur (compute-next-genr g)
|
||||
(inc i)))))
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
(def rules
|
||||
{
|
||||
[0 0 0] 0
|
||||
[0 0 1] 0
|
||||
[0 1 0] 0
|
||||
[0 1 1] 1
|
||||
[1 0 0] 0
|
||||
[1 0 1] 1
|
||||
[1 1 0] 1
|
||||
[1 1 1] 0
|
||||
})
|
||||
|
||||
(defn nextgen [gen]
|
||||
(concat [0]
|
||||
(->> gen
|
||||
(partition 3 1)
|
||||
(map vec)
|
||||
(map rules))
|
||||
[0]))
|
||||
|
||||
; Output time!
|
||||
(doseq [g (take 10 (iterate nextgen [0 1 1 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0]))]
|
||||
(println g))
|
||||
Loading…
Add table
Add a link
Reference in a new issue