From: James Edward Gray II Date: 2005-11-14T23:35:20+09:00 Subject: Re: Recursive functions On Nov 14, 2005, at 8:21 AM, Brian Schr�der wrote: > Be carefull. Spoiler below Brian was faster than me. My own attempt follows, again, a spoiler... . . . . . . . . . . . . . . . . . . . . . . . James Edward Gray II def combine( triplets, combinations = [""] ) chrs = triplets.shift.split("") combos = combinations.map { |combo| chrs.map { |chr| combo + chr } }.flatten combos.delete_if do |start| !$dict[start.length + triplets.length].any? { |word| word =~ /^# {start}/ } end if triplets.empty? combos else combine(triplets, combos) end end warn "Loading dictionary..." if $DEBUG $dict = Hash.new { |words, len| words[len] = Array.new } File.foreach("/usr/share/dict/words") do |line| word = line.downcase.delete("^a-z") $dict[word.length] << word end warn "Loaded." if $DEBUG warn "Building word list:" if $DEBUG puts DATA.each_line("") do |line| puts combine(line.strip.downcase.split) puts end __END__ ubc deg lap pyq ved run pac ken alm mli rnt alg