public
Last active

ant dna skill-processor

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.