Forum: Ruby Re: is this a good way to find anagrams?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
wrong (Guest)
on 2005-12-10 08:16
(Received via mailing list)
i goofed up my thread by using the word "anagram" incorrectly, or too
loosely...
i also wanted to find all the smaller words that i can make with the
letters that i have.
for example i would like for "monkey" to return with "monk" and "key"
and "money" and so on, not just 6 letter
words.

i think this makes it so you can't use the methods where you sort
everything first, which i discovered didnt work
all the time if you want smaller words too.
if you sort "monkey" you get "ekmnoy" but if you sort "monkeys" you get
"ekmnosy", which means if your letters
are "monkeys", you wont get "monkey" back. that s is a big monkey wrench
between o and y.

maybe i should do the sort first way on the words in the dictionary that
have the same amount of letters, and
then do some other way on all the words that have less letters, and skip
all the words that are too long?

i'm still glad for all the nice anagram (in the strict sense) finder
code in this thread. this is the best list ever.

----- Original Message -----
From: Brian Schröder <removed_email_address@domain.invalid>
Date: Friday, December 9, 2005 4:15 am
Subject: Re: is this a good way to find anagrams?
Martin DeMello (Guest)
on 2005-12-12 10:04
(Received via mailing list)
removed_email_address@domain.invalid wrote:
> i goofed up my thread by using the word "anagram" incorrectly, or too
> loosely...  i also wanted to find all the smaller words that i can
> make with the letters that i have.  for example i would like for
> "monkey" to return with "monk" and "key" and "money" and so on, not
> just 6 letter words.

One interesting way to do subset finding in words is to hook up a fast
bignum library (I think ruby/gsl should do this), and index each letter
with a prime number, so that a word maps to the product of its letters.
Then word_b contains word_a if number_b % number_a == 0.

martin
This topic is locked and can not be replied to.