Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,7 @@
|
|||
(def c 100) ;number of children in each generation
|
||||
(def p 0.05) ;mutation probability
|
||||
|
||||
(def target "METHINKS IT IS LIKE A WEASEL")
|
||||
(def tsize (count target))
|
||||
|
||||
(def alphabet " ABCDEFGHIJLKLMNOPQRSTUVWXYZ")
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(defn fitness [s] (count (filter true? (map = s target))))
|
||||
(defn perfectly-fit? [s] (= (fitness s) tsize))
|
||||
|
||||
(defn randc [] (rand-nth alphabet))
|
||||
(defn mutate [s] (map #(if (< (rand) p) (randc) %) s))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(loop [generation 1, parent (repeatedly tsize randc)]
|
||||
(println generation, (apply str parent), (fitness parent))
|
||||
(if-not (perfectly-fit? parent)
|
||||
(let [children (repeatedly c #(mutate parent))
|
||||
fittest (apply max-key fitness parent children)]
|
||||
(recur (inc generation), fittest))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue