There are two commented lines that are only necessary if you want to guarantee that the keypress sequence for the word will uniquely identify that word (ie, feed and deed would both be excluded - while they both require 4 presses of 3, it's not sufficient to uniquely identify the word requested). With my input data, it made no difference. 263 or 317 bytes depending on whether you want the uniqueness. n={};%w{2ABC 3DEF 4GHI 5JKL 6MNO 7PQRS 8TUV 9WXYZ}.each{|a|a.scan(/./){|c|n[c]=a[0..0]}} m=[]; #z={} ARGF.collect{|w|w.strip!;if !((k=w.upcase.split(//).map{|c|n[c]})).compact! #z[k]=(z[k]||0)+1;end;[w,k]}.each{|w,k|if z[k]==1 s = k.uniq.size;m[s]=[(m[s]||""),w].sort_by{|a|a.length}[-1];end} m.each_with_index{|*x|p x} Results in: ["", 0] ["deeded", 1] ["represses", 2] ["shepherdesses", 3] ["presumptuousness", 4] ["transubstantiation", 5] ["misrepresentations", 6] ["electroencephalographs", 7] ["uncharacteristically", 8] -----Original Message----- From: John Carter [mailto:john.carter / tait.co.nz] Sent: Thursday, 6 October 2005 1:33 PM To: ruby-talk ML Subject: Ruby Golf on Lazy T9 Words. Assuming you are running Linux and have a list of valid English words in the file /usr/share/dict/words or someplace or something similar. Assume you have a cellphone with T9 predictive text input. For those that don't, cellphones have each key overloaded to mean several things. eg. On my Sharp GX-15 2 also means A,B,C 3 also means D,E,F 4 also means G,H,I 5 also means J,K,L 6 = M,N,O 7 = P,Q,R,S 8 = T,U,V 9 = W,X,Y,Z In T9 mode I can type in 43556 and it only finds one word in its dictionary that can be made with combination {G,H,I}{D,E,F}{J,K,L}{J,K,L}{M,N,O} and that is HELLO Which is a lost faster than typing 4433555555666. How ever, some words like "high", can be entered by just bouncing on one key ... 4444. Your mission, should you choose to accept, is to write the shortest ruby program that will find the longest word in the dictionary that can be produced by... * repeatedly typing one key * Can be produced by just using only two keys. * Can be produced by just using only three keys. * Can be produced by just using only four keys. * .... John Carter Phone : (64)(3) 358 6639 Tait Electronics Fax : (64)(3) 359 4632 PO Box 1645 Christchurch Email : john.carter / tait.co.nz New Zealand Carter's Clarification of Murphy's Law. "Things only ever go right so that they may go more spectacularly wrong later." From this principle, all of life and physics may be deduced. ##################################################################################### This email has been scanned by MailMarshal, an email content filter. #####################################################################################