Jump to content

Evolutionary algorithm: Difference between revisions

Line 492:
(defn perfectly-fit? [s] (= (fitness s) (count target)))
 
(defn randc [] (get alphabet (rand-int (count alphabet)))) ; or simply (rand-nth alphabet) in Clojure 1.2
(defn mutate [s] (map #(if (< (rand) p) (randc) %) s))</lang>
Finally evolve. At each generation, print the generation number, the parent, and the parent's fitness.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.