From: William James Date: 2005-09-02T05:04:04+09:00 Subject: Re: Word Chains (#44) Simon Kr�ger wrote: > One of the programs that crashed was my second submission (it wasn't > even labeled as solution) that was just a try to make it as short as > possible (while still being kind of fast) and the change in interface > was clearly mentioned: "the dictionary is the optional third parameter, > no -d" Added a line to your program that lets it accept -d. Since this program is so short compared to the others, I consider it quite noteworthy. p=$*.index('-d') and $* << $*[p+1] and $*[p,2]=[] dict, len = Hash.new{|h,k|h[k] = []}, ARGV[0].size IO.foreach(ARGV[2] || 'words.txt') do |w| w.chomp! if w.size != len then next else s = w.dup end (0...w.size).each{|i|s[i]=?.; dict[s] << w; s[i]=w[i]} end t, known = {ARGV[1] => 0}, {} while !known.merge!(t).include?(ARGV[0]) t = t.keys.inject({}){|h, w|(0...w.size).each{|i| s=w.dup; s[i]=?.; dict[s].each{|l|h[l] = w if !known[l]}};h} warn 'no way!' or exit if t.empty? end puts w = ARGV[0]; puts w while (w = known[w]) != 0