Word scrambling..

I saw this short in-between-programmes thing on National Geographic channel where they showed that when you read, only the first and last letter in each word is really important – the brain does some crazy pattern matching on the letters in the middle and recognizes the words anyway without too much trouble!

So I wrote this little Ruby script to check it out myself.

I msut say taht it is rllaey ture waht tehy say. the biran is pertty aminazgĀ 

hree is the spcrit if you wnat to try it out yurseolf

# word scrambler

str = ARGV[0]
srand(Time.now.usec)
strs = str.split(' ')
res = ''
strs.each {|curword|
  scramble = String.new(curword)
  len = curword.length
  if (len > 3)
    begin
      sel = curword[1..len-2].split('')
      (1..len-2).each {|c|
        idx = rand(sel.size)
        scramble[c] = sel[idx]
        sel.delete_at(idx)
      }
    end while (curword == scramble)
  end
  res += scramble + ' '
}

puts res

Leave a Reply