RE: RE: Be a monkey!by gumpu (Friar)
|on Aug 31, 2000 at 12:13 UTC||Need Help??|
Better yet, how about having it try to create a perl script and periodically eval'ing the result? *grin* "It's not obfuscated, it's written by my monkey!
They actually use a technique a bit similar to the monkeys system to breed programs. It's called genetic programming.
It can be used to breed program that are good at a certain task. Say for instance sorting a file or solving some math problem, or writing shakespeare :)
Applied to perl it would go something like this:
You have a population of 1000 individuals. Each individual is a program of say 100 lines of perl code. These lines are chosen randomly at the begin.
Each population goes through a number of generations. During each generation the fitness of each individual (perl program) is tested.
It is tested by running the program and evaluating how well it perform the target task. In the case of sorting it is tested of the file was sorted correctly and how fast the program sorted. Or how well it writes literature in case of the Shakespeare problem.
The 500 best programs are allowed to mate and produce two childern. For this a pair of programs is chosen at random. A random line number is chosen. Say n. Child 1 is created out of the first n lines of parent 1 and the remaining 100-n lines of parent 2. Child two is made out of the first n lines of parent 2 and the remaining 100-n lines of parent 1. Sometimes a line of code is also mutated, (changed a bit), this introduces more diversity.
Now all the parents die. What remains is a population of 1000 childern, a new generation. Which are hopefully better addapted to solving the given problem. The process is repeated.
With each generation the individuals will become better and better (on average) at solving the given problem. It works much like evolution works, survival of the fittest, with a bit of mutation.
The only thing you have to do solve a problem is specifiy is a function that defines how good a program is at solving the given problem.
Which is easy in most cases, though in case of the Shakespeare problem finding such a function is probably more difficult, cause how do you define good literature :)