Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d2537e5
Showing
6 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pom.xml | ||
*jar | ||
/lib/ | ||
/classes/ | ||
.lein-failures | ||
.lein-deps-sum |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# tryclojure | ||
|
||
FIXME: write description | ||
|
||
## Usage | ||
|
||
FIXME: write | ||
|
||
## License | ||
|
||
Copyright (C) 2011 FIXME | ||
|
||
Distributed under the Eclipse Public License, the same as Clojure. |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(defproject evolve "1.0.0-SNAPSHOT" | ||
:description "String Evolution" | ||
:dependencies [[org.clojure/clojure "1.2.1"] | ||
[org.clojure/clojure-contrib "1.2.0"]] | ||
:main evolve.core) |
Binary file not shown.
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(ns evolve.core | ||
(:require [clojure.contrib.string :as contstr]) | ||
(:gen-class)) | ||
|
||
(defn fitness [target] | ||
(fn [source] | ||
(apply + | ||
(map | ||
(fn [x y] (* (- x y) (- x y))) | ||
(contstr/codepoints source) | ||
(contstr/codepoints target))) )) | ||
|
||
(defn mutate [source] | ||
(let [i (rand-int (count source))] | ||
(str | ||
(subs source 0 i) (char (inc (int (nth source i)))) (subs source (inc i))))) | ||
|
||
(defn evolve | ||
[source fitness] | ||
(first | ||
(filter #(< (fitness %) (fitness source)) | ||
(iterate mutate source)))) | ||
|
||
(defn start | ||
[generations source target] | ||
(nth (iterate #(evolve % (fitness target)) source) generations)) | ||
|
||
(defn -main [& args] | ||
(println (start 500 "dlk33ndoemgl" "Hello World!"))) |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(ns evolve.test.core | ||
(:use [evolve.core]) | ||
(:use [clojure.test])) | ||
|
||
(deftest replace-me ;; FIXME: write | ||
(is false "No tests have been written.")) |