40 lines
945 B
Plaintext
40 lines
945 B
Plaintext
'EVOLUTION
|
|
|
|
target="METHINKS IT IS LIKE A WEASEL"
|
|
le=len target
|
|
progeny=string le,"X"
|
|
|
|
quad seed
|
|
declare QueryPerformanceCounter lib "kernel32.dll" (quad*q)
|
|
QueryPerformanceCounter seed
|
|
|
|
Function Rand(sys max) as sys
|
|
mov eax,max
|
|
inc eax
|
|
imul edx,seed,0x8088405
|
|
inc edx
|
|
mov seed,edx
|
|
mul edx
|
|
return edx
|
|
End Function
|
|
|
|
sys ls=le-1,cp=0,ct=0,ch=0,fit=0,gens=0
|
|
|
|
do '1 mutation per generation
|
|
i=1+rand ls 'mutation position
|
|
ch=64+rand 26 'mutation ascii code
|
|
if ch=64 then ch=32 'change '@' to ' '
|
|
ct=asc target,i 'target ascii code
|
|
cp=asc progeny,i 'parent ascii code
|
|
'
|
|
if ch=ct then
|
|
if cp<>ct then
|
|
mid progeny,i,chr ch 'carry improvement
|
|
fit++ 'increment fitness
|
|
end if
|
|
end if
|
|
gens++
|
|
if fit=le then exit do 'matches target
|
|
end do
|
|
print progeny " " gens 'RESULT (range 1200-6000 generations)
|