------ extPart_000_035A_01C519BA.F4D9C0D0 Content-Type: text/plain; charset S-ASCII" Content-Transfer-Encoding: 7bit Here is the new version. I just needed to chomp the dictionary words. I wrote and tested it using cygwin and my own test dictionary, IO.readlines seems to keep the \n for each line on linux but not on cygwin. The output against /usr/share/dict/words doesn't seem too helpful since each letter is listed as its own word. Sorry it's so slow running against a large dictionary. -----Original Message----- From: James Edward Gray II [mailto:james / grayproductions.net] Sent: Wednesday, February 23, 2005 1:23 PM To: ruby-talk ML Subject: Re: [SOLUTION] [QUIZ] 1-800-THE-QUIZ (#20) On Feb 22, 2005, at 4:04 PM, Lee Marlow wrote: > Attached is my solution. Just FYI, I get some pretty unusual output when I run this on the quiz phone number using /usr/share/dict/words as my dictionary. Here's a little of what I see: $ echo '873.7829' | ruby phonewords.rb -d /usr/share/dict/words 8-Q -7-TA URF -T -Y T -3-PU -Z U -ES -AW UR -7-T -Y US -Q -A U -3-P -2-Z URD -U ... James Edward Gray II ------ extPart_000_035A_01C519BA.F4D9C0D0 Content-Type: application/octet-stream; name honewords.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename honewords.rb" #!/usr/bin/env ruby require 'set' require 'optparse' dict il ARGV.options do |opts| opts.banner Usage: ruby #{__FILE__} [options] [input files]" opts.on('Options:') opts.on('--dictionary DICTFILE', '-d', 'Specify dictionary file') { |file| File.open(file) { |f| dict .readlines } } opts.on("--help", "-h", "This text") { puts opts; exit 0 } opts.parse! end l2n } %w{ABC DEF GHI JKL MNO PQRS TUV WXYZ}.each_with_index { |letters, num| letters.scan(/./).each { |c| l2n[c] #{num + 2}" } } dict w{use ruby a quick brown fox jumped over the lazy laz laxx dog lazyfox f azyfox} unless dict num_dict } dict.each { |word| num_word ' upword ord.chomp.upcase upword.scan(/./).each { |c| num_word << l2n[c] } (num_dict[num_word] || ]) << upword } def build_word_list(position_list, phnumber, words et.new, word ') position ord.length - word.count('-') if position > osition_list.size word.chop! while word[-1, 1] '-' words << word return end position_list[position].each { |word_ary| next unless word_ary word_ary.each { |w| new_word ord.empty? ? "#{w}" : "#{word}-#{w}" build_word_list(position_list, phnumber, words, new_word) build_word_list(position_list, phnumber, words, "#{new_word}-#{phnumber[position + w.length, 1]}") } } words end while phone ets next if phone.gsub!(/[^\d]/, '').empty? digits hone.scan(/./) position_list rray.new(digits.size) digits.each_with_index { |d, i| length_list osition_list[i] rray.new(digits.size - i) num_word ' (i...digits.size).each { |j| num_word << digits[j] length_list[j - i] um_dict[num_word] } } build_word_list(position_list, phone, build_word_list(position_list, phone), phone[0,1]).each { |w| puts w } end ------ extPart_000_035A_01C519BA.F4D9C0D0--