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.




T = 0                                  ' Address of target
L = 28                                 ' Length of string
P = T + L                              ' Address of parent
R = 6                                  ' Mutation rate in percent
C = 7                                  ' Number of children
B = 0                                  ' Best rate so far
 
Proc _Initialize                       ' Initialize
 
Do                                     ' Now start mutating
  I = 0                                ' Nothing does it better so far
 
  For x = 2 To C+1                     ' Addresses of children
    Proc _MutateDNA (x, P, R)          ' Now mutate their DNA
    F = FUNC(_Fitness (x, T))          ' Check for fitness
    If F > B Then B = F : I = x        ' If fitness of child is better
  Next                                 ' Make it the best score
 
  If I Then                            ' If a better child was found
    Proc _MakeParent (P, I)            ' Make the child the parent
    Proc _PrintParent (P)              ' Print the new parent
  EndIf
 
  Until B = L                          ' Until top score equals length
Loop
 
End
 
 
_MutateDNA Param(3)                    ' Mutate an entire DNA
  Local(1)
 
  For d@ = 0 to L-1                    ' For the entire string
    If c@ > Rnd(100) Then              ' If mutation rate is met
       @(a@*L+d@) = Ord("A") + Rnd(27) ' Mutate the gene
    Else
       @(a@*L+d@) = @(b@+d@)           ' Otherwise copy it from the parent
    EndIf
  Next
Return
 
 
_Fitness Param(2)                      ' Check for fitness
  Local(2)
 
  c@ = 0                               ' Fitness is zero
  For d@ = 0 to L-1                    ' For the entire string
    If @(a@*L+d@) = @(b@+d@) Then c@ = c@ + 1
  Next                                 ' If string matches, increment score
Return (c@)                            ' Return the fitness
 
 
_MakeParent Param(2)                   ' Make a child into a parent
  Local(1)
 
  For c@ = 0 to L-1                    ' For the entire string
    @(a@+c@) = @(b@*L+c@)              ' Copy the DNA gene by gene
  Next
Return
 
 
_PrintParent Param(1)                  ' Print the parent
  Local(1)
 
  For b@ = 0 to L-1                    ' For the entire string
    If (@(a@+b@)) > Ord ("Z") Then
      Print " ";                       ' Cater for the space
    Else
      Print CHR(@(a@+b@));             ' Print a gene
    EndIf
  Next
 
  Print                                ' Issue a linefeed
Return
 
 
_Initialize                            ' Initialize target and parent
  @(0)=Ord("M")                        ' Initialize target (long!)
  @(1)=Ord("E")                        ' Character by character
  @(2)=Ord("T")
  @(3)=Ord("H")
  @(4)=Ord("I")
  @(5)=Ord("N")
  @(6)=Ord("K")
  @(7)=Ord("S")
  @(8)=Ord("Z")+1
  @(9)=Ord("I")
  @(10)=Ord("T")
  @(11)=Ord("Z")+1
  @(12)=Ord("I")
  @(13)=Ord("S")
  @(14)=Ord("Z")+1
  @(15)=Ord("L")
  @(16)=Ord("I")
  @(17)=Ord("K")
  @(18)=Ord("E")
  @(19)=Ord("Z")+1
  @(20)=Ord("A")
  @(21)=Ord("Z")+1
  @(22)=Ord("W")
  @(23)=Ord("E")
  @(24)=Ord("A")
  @(25)=Ord("S")
  @(26)=Ord("E")
  @(27)=Ord("L")
 
  Proc _MutateDNA (P/L, P, 100)          ' Now mutate the parent DNA
Return