Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstockton committed Oct 9, 2011
0 parents commit d2537e5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
pom.xml
*jar
/lib/
/classes/
.lein-failures
.lein-deps-sum
13 changes: 13 additions & 0 deletions README
@@ -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.
5 changes: 5 additions & 0 deletions project.clj
@@ -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 added src/evolve/.core.clj.swp
Binary file not shown.
29 changes: 29 additions & 0 deletions src/evolve/core.clj
@@ -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!")))
6 changes: 6 additions & 0 deletions test/evolve/test/core.clj
@@ -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."))

0 comments on commit d2537e5

Please sign in to comment.