Skip to content

Instantly share code, notes, and snippets.

@TomK32
Created August 7, 2009 20:04
Show Gist options
  • Save TomK32/164135 to your computer and use it in GitHub Desktop.
Save TomK32/164135 to your computer and use it in GitHub Desktop.
ant dna skill-processor
# computed sample at https://gist.github.com/164138
genes = %w(A C G T)
strength = ".AG. GC.. ...A ..GC AC.. GT.. T.TC ...."
size = "CG.. .... ...C ..T. ..AC .... ...C ..A."
weight = "TC.C C... ..CG TG.C .... GC.A .GG. .AAA"
ant = ''
(0..31).each do |i|
ant += genes[rand(4)]
ant += ' ' if ((i % 4) == 3)
end
puts ant
ant = ant.split('')
ant_size = 0
size.split('').each_with_index do |value,key|
next if value == '.' or value == ' '
ant_size += 1 if ant[key] == value
ant_size -= 1 if ant[key] == genes[(genes.index(value) + 2) % 4]
end
puts 'size: %i ' % ant_size
ant_strength = 0
strength.split('').each_with_index do |value,key|
next if value == '.' or value == ' '
ant_strength += 1 if ant[key] == value
ant_strength -= 1 if ant[key] == genes[(genes.index(value) + 2) % 4]
end
puts 'strength: %i ' % ant_strength
ant_weight = 0
weight.split('').each_with_index do |value,key|
next if value == '.' or value == ' '
ant_weight += 1 if ant[key] == value
ant_weight -= 1 if ant[key] == genes[(genes.index(value) + 2) % 4]
end
puts 'weight: %i ' % ant_weight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment