```[Ruby Quiz <james / grayproductions.net>, 2004-12-17 14.45 CET]
> In Scrabble parlance, a 'bingo stem' is defined as a set of six
> letters that combines with a large fraction of the alphabet to anagram
> to valid seven letter words (a 'bingo' is a move using all seven tiles
> on your rack). For instance, one of the more prolific stems, SATIRE,
> combines with twenty letters, A, B, C, D, E, F, G, H, I, K, L, M, N,
> O, P, R, S, T, V, W (forming words like ASTERIA, BAITERS, RACIEST
> ...).
>
> Write a program that, given a word list and a cutoff n, finds all 6
> letter stems that combine with n or more letters, sorted in order of
> how many distinct letters they combine with.

Here is a possible (I hope correct) solution. SATIRE combines only with 16
letters according to my dictionary.

DICT = "/usr/share/dict/words"
CUTOFF = ARGV[0].to_i

STEMS = {}

File.open(DICT) do |f|
f.each do |word|
word.chomp!
next if word.length != 7
word.downcase!
letters = word.split(//).sort!
uniques = letters.uniq
word = letters.join
uniques.each do |letter|
stem = word.sub(/#{letter}/, "")
(STEMS[stem] ||= {})[letter] = 1
end
end
end

result = STEMS.delete_if { |k,v| v.size < CUTOFF }.
sort_by { |k,v| v.size }.
reverse!.
collect! { |k,v| [k, v.size] }

result.each do |stem, combining| puts "#{stem} #{combining}" end

```