Inspiration

I thought it would be cool to get a code to write code

What it does

It randomly generates code in a custom language I created and evolves the code using natural selection so that it solves a given specific problem.

How I built it

I have used a Genetic Algorithm to iterate over generations of code and a Squared Error Loss Function to choose the survivor of each generation.

The code is like DNA. It is a sequence of operations, aka genes. Each gene consist of 3 bases. They are for Operation, Input and Assignment accordingly. An Operation is a character between '0' and '6': 0 -> assign 1 -> add 2 -> subtract 3 -> multiply 4 -> divide 5 -> root 6 -> power

An Input is either a character between '0' and '9', representing literal integer value, or a character between 'A' and 'F', representing variables.

An Assignment is a character between 'A' and 'F' representing variables. 'A' is initialized with the input and 'B' is where the output is read from. Every variable besides 'A' is initialized with 0.

Here's an example code that solves f(x)=x*x-1:

3AA 1AB 21B

  • Multiply A(input) by itself.
  • Add A to B.
  • Subtract 1 from B

An Interesting Idea

If a go-to operation was to be included, it would be a turing-complete language which means that this program could solve computer science problems given enough time and supervised data.

I actually tried implementing this but it did not give very good results since making if's or for's out of go-to statements require a perfect coherence between several independent parts of the code.

Even if it seems like hard task, I can't see any reason why there shouldn't be a solution to this.

Challenges I ran into

Structuring a syntax-error free language, structuring the learning modal

Accomplishments that I'm proud of

It works better than I thought it would

What I learned

Future is near!

What's next for evogrammer

World domination, or getting the turing-complete part to work, whichever is faster.

Built With

Share this project:

Updates