Starting with:

 The target string: "METHINKS IT IS LIKE A WEASEL".
 An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent).
 A fitness function that computes the ‘closeness’ of its argument to the target string.
 A mutate function that given a string and a mutation rate returns a copy of the string, with some characters probably mutated.
 While the parent is not yet the target:
 copy the parent C times, each time allowing some random probability that another character might be substituted using mutate.
 Assess the fitness of the parent and all the copies to the target and make the most fit string the new parent, discarding the others.
 repeat until the parent converges, (hopefully), to the target.


See also

   Wikipedia entry:   Weasel algorithm.
   Wikipedia entry:   Evolutionary algorithm.

Note: to aid comparison, try and ensure the variables and functions mentioned in the task description appear in solutions



A cursory examination of a few of the solutions reveals that the instructions have not been followed rigorously in some solutions. Specifically,

 While the parent is not yet the target:
 copy the parent C times, each time allowing some random probability that another character might be substituted using mutate.
Note that some of the the solutions given retain characters in the mutated string that are correct in the target string. However, the instruction above does not state to retain any of the characters while performing the mutation. Although some may believe to do so is implied from the use of "converges"

(:* repeat until the parent converges, (hopefully), to the target.

Strictly speaking, the new parent should be selected from the new pool of mutations, and then the new parent used to generate the next set of mutations with parent characters getting retained only by not being mutated. It then becomes possible that the new set of mutations has no member that is fitter than the parent!

As illustration of this error, the code for 8th has the following remark.

Create a new string based on the TOS, changing randomly any characters which
don't already match the target:

NOTE: this has been changed, the 8th version is completely random now

Clearly, this algo will be applying the mutation function only to the parent characters that don't match to the target characters!

To ensure that the new parent is never less fit than the prior parent, both the parent and all of the latest mutations are subjected to the fitness test to select the next parent.




 
\ RosettaCode challenge http://rosettacode.org/wiki/Evolutionary_algorithm
\ Responding to the criticism that the implementation was too directed, this
\ version does a completely random selection of chars to mutate
 
var gen
\ Convert a string of valid chars into an array of char-strings:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ " null s:/ var, valid-chars
 
\ How many mutations each generation will handle; the larger, the slower each
\ generation but the fewer generations required:
300 var, #mutations
23 var, mutability
 
: get-random-char
  valid-chars @
  27 rand-pcg n:abs swap n:mod
  a:@ nip ;
 
: mutate-string \ s -- s'
  ( 
    rand-pcg mutability @ n:mod not if
     drop get-random-char
    then
  ) s:map ;
 
: mutate \ s n -- a 
  \ iterate 'n' times over the initial string, mutating it each time
  \ save the original string, as the best of the previous generation:
  >r [] over a:push swap
  (
  tuck mutate-string
  a:push swap
  ) r> times drop ;
 
\ compute Hamming distance of two strings:
: hamming \ s1 s2 -- n
  0 >r
  s:len n:1-
  (
   2 pick over s:@ nip
   2 pick rot s:@ nip
   n:- n:abs r> n:+ >r
  ) 0 rot loop
  2drop r> ;
 
var best
: fitness-check \ s a -- s t
  10000 >r
  -1 best !
  (
   \ ix s ix s'
    2 pick hamming 
   r@ 
   over n:> if
      rdrop >r
      best !
   else
      2drop
   then
  )
  a:each
  rdrop best @  a:@ nip  ;
 
 
: add-random-char \ s -- s'
  get-random-char s:+ ;
 
\ take the target and make a random string of the same length
: initial-string \ s -- s
  s:len "" swap  
  ' add-random-char
  swap times ;
 
: done? \ s1 s2 -- s1 s2 | bye
  2dup s:= if 
   "Done in " . gen @ . " generations" . cr ;;;
  then ;
 
: setup-random
  rand rand rand-pcg-seed ;
 
: evolve 
  1 gen n:+!
  \ create an array of #mutations strings mutated from the random string, drop the random
  #mutations @ mutate  
  \ iterate over the array and pick the closest fit:
  fitness-check 
  \ show this generation's best match:
  dup . cr 
  \ check for end condition and continue if not done:
  done? evolve ;
 
"METHINKS IT IS LIKE A WEASEL"  
setup-random initial-string evolve bye