Skip to content

Commit

Permalink
go
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed Sep 12, 2020
1 parent d0e24b1 commit 8626dde
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This repository contains a simple implementation of a genetic algorithm for evo

In order to use this, we first need to create a "phenotype" representation which contains the dna `[]byte`. It should implement the `Evolver` interface which contains `Genome()` and `Evolve()` methods, in the example here we are creating a simple text which contains the binary representation of the text itself.

```
```go
// Text represents a text with a dna (text itself in this case)
type text struct {
dna []byte
Expand All @@ -35,8 +35,7 @@ func (t *text) String() string {
}
```
Next, we'll need a fitness function to evaluate how good a genome is. In this example we're creating a fitness function for an abritrary string which simply returns a `func(Evolver) float32`
```
```go
// fitnessFor returns a fitness function for a string
func fitnessFor(text string) evolve.Fitness {
target := []byte(text)
Expand All @@ -54,7 +53,7 @@ func fitnessFor(text string) evolve.Fitness {

Finally, we can wire everything together by using `New()` function to create a population, and evolve it by repeatedly calling `Evolve()` method as shown below.

```
```go
func main() {
const target = "Hello World"
const n = 200
Expand Down

0 comments on commit 8626dde

Please sign in to comment.