Created
January 10, 2018 19:08
-
-
Save eaglgenes101/5b60fe008a8b5741712683d710a8043b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env julia | |
# Load the moby dick source into one buffer | |
base = read("whale.txt") | |
# Generate random fuzz mutation | |
mutate(genome) = (genome .+ sprand(UInt8, size(genome)[1], .000001)) .% 256 | |
patch(original, genome) = (original .+ genome) .% 256 | |
crossover(gen1, gen2) = map(a->rand(0:1)==0?gen1[a]:gen2[a], 1:size(gen1)) | |
function fitness(genome) | |
(so,si,pr) = readandwrite(`xz -z0 -`) | |
write(si, patch(base, genome)) | |
close(si) | |
wait(pr) | |
size = read(so) | |
compressed = size(read(pipeline(`xz -z0 -`,stdin=patch(base, genome))))[1] | |
diff = nnz(genome) | |
return diff - 2*compressed | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment