midwifetoad
Posts: 4003 Joined: Mar. 2008
|
Here's my BASIC interpretation: Quote | Sub Weasel() Dim AlphabetText As String Dim Target As String, Parent As String, BestChild As String, Child As String Dim I As Integer, Best As Integer, Generation As Integer, Copies As Integer AlphabetText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ " Target = "METHINKS IT IS LIKE A WEASEL" Copies = 100 Parent = "" Best = 0 For I = 1 To Len(Target) Parent = Parent + RandChar(AlphabetText) Next Debug.Print Parent Generation = 1 While Best < Len(Target) For I = 1 To Copies Child = Parent Mid(Child, RandNum(Len(Child)), 1) = RandChar(AlphabetText) If SameLetters(Child, Target) > Best Then BestChild = Child Best = SameLetters(Child, Target) End If Next Parent = BestChild If Generation Mod 10 = 0 Then Debug.Print CStr(Generation) + ":" + Parent Generation = Generation + 1 Wend Debug.Print CStr(Generation) + ":" + Parent End Sub
Function RandChar(AlphabetText As String) As String Dim c As Integer Randomize c = Int((27 * Rnd) + 1) RandChar = Mid(AlphabetText, c, 1) End Function
Function RandNum(I As Integer) As Integer Randomize RandNum = Int((I * Rnd) + 1) End Function
Function SameLetters(Child As String, Target As String) As Integer Dim L As Integer, I As Integer L = 0 For I = 1 To Len(Child) If Mid(Child, I, 1) = Mid(Target, I, 1) Then L = L + 1 End If Next SameLetters = L End Function |
It works, but it can't be Dawkins' code, because only one character per child can mutate. The effective mutation rate is approximately 4 percent, which gives decent results, but conceptually it isn't Dawkins.
-------------- Any version of ID consistent with all the evidence is indistinguishable from evolution.
|