Babel.rb

From BenningtonWiki
Jump to: navigation, search

<source lang="ruby">

  1. !/usr/bin/env ruby -w

alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",

           "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]

magic_name = "JOEHOLT"

count = 0 length = magic_name.length interesting_match_threshold = (length * 0.75).to_i

Thread.new do

   loop do
       sleep(15)
       print "#{count}\n"
   end

end

loop do

   count += 1
   guess_name = ""
   matches = 0
   length.times do |i|

letter = alphabet[rand(26)]

   	guess_name << letter
   	matches += 1 if letter[0] == magic_name[i]
   end
   print "#{count}, #{guess_name} -- matches #{matches}\n" if matches >= interesting_match_threshold
   break if matches == length

end

print "Found you.\n"

</source>