------art_99318_13244856.1186340612444
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Here is my solution. I tried to make things easy to follow...

First, I create a regular expression to match all words in a number base.
This method basically generates a regex matching single words consisting of
letters in the base. Matching is case insensitive:

def get_regexp(base_num)
  # Get number of letters in the base
  num_letters  ase_num - 10
  num_letters  6 if num_letters > 26 # Cap at all letters in alphabet
  return nil if num_letters < 1        # Nothing would match

  # Create a regular expression to match all letters in the base
  end_c  "z"[0] - (26 - num_letters)).chr # Move back from 'z' until reach
last char in the base
  regexp_str  ^([a-#{end_c}])+$"          # Always starts at 'a'
  Regexp.new(regexp_str, "i")
end

Next we have a "main" method to read file, base, and length parameters from
the command line, and find all words. The code uses a boilerplate
read_words_from_file method to read the words:

if ARGV.size ! 
  puts "Usage: words_as_numbers.rb word_file number_base
minimum_word_length"
else
  word_file  RGV[0]
  base  RGV[1].to_i
  word_length  RGV[2].to_i
  regexp  et_regexp(base)

  # Find all words
  if (regexp ! il)
    for word in read_words_from_file(word_file)
      if word.size > ord_length
        puts word if regexp.match(word)
      end
    end
  end
end

And here is a test run:
>words_as_numbers.rb linux.words.txt 16 6
accede
acceded
beaded
bedded
beefed
decade
deeded
deface
facade
facaded

Its interesting that each subsequent base (11, 12, etc) contains all words
in the previous iteration. It would be interesting to analyze the frequency
of words found at each iteration, or create a visualization of the process.
Anyway, here is a pastie of everything: http://pastie.caboo.se/85060

Thanks,

Justin

On 8/3/07, Ruby Quiz <james / grayproductions.net> wrote:
>
> The three rules of Ruby Quiz:
>
> 1.  Please do not post any solutions or spoiler discussion for this quiz
> until
> 48 hours have passed from the time on this message.
>
> 2.  Support Ruby Quiz by submitting ideas as often as you can:
>
> http://www.rubyquiz.com/
>
> 3.  Enjoy!
>
> Suggestion:  A [QUIZ] in the subject of emails about the problem helps
> everyone
> on Ruby Talk follow the discussion.  Please reply to the original quiz
> message,
> if you can.
>
>
> --------------------
>
> by Morton Goldberg
>
> When working with hexadecimal numbers it is likely that you've noticed
> some hex
> numbers are also words. For example, 'bad' and 'face' are both English
> words and
> valid hex numbers (2989 and 64206, respectively, in decimal). I got to
> thinking
> that it would be interesting to find out how many and which hex numbers
> were
> also valid English words. Of course, almost immediately I started to think
> of
> generalizations. What about other bases? What about languages other than
> English?
>
> Your mission is to pick a word list in some language (it will have be one
> that
> uses roman letters) and write Ruby code to filter the list to extract all
> the
> words which are valid numbers in a given base. For many bases this isn't
> an
> interesting task--for bases 2-10, the filter comes up empty; for bases
> 11-13,
> the filter output is uninteresting (IMO); for bases approaching 36, the
> filter
> passes almost everything (also uninteresting IMO). However, for bases in
> the
> range from 14 to about 22, the results can be interesting and even
> surprising,
> especially if one constrains the filter to accept only words of some
> length.
>
> I used `/usr/share/dict/words` for my word list. Participants who don't
> have
> that list on their system or want a different one can go to Kevin's Word
> List
> Page (http://wordlist.sourceforge.net/) as a source of other word lists.
>
> Some points you might want to consider: Do you want to omit short words
> like 'a'
> and 'ad'? (I made word length a parameter). Do you want to allow
> capitalized
> words (I prohibited them)? Do you want to restrict the bases allowed (I
> didn't)?
>
>

------art_99318_13244856.1186340612444--