# Re: is this a good way to find anagrams?

**URL:** <https://www.ruby-forum.com/t/re-is-this-a-good-way-to-find-anagrams/49929>\
**Category:** Ruby\
**Created:** [December 10, 2005, 7:16am UTC](https://www.ruby-forum.com/t/re-is-this-a-good-way-to-find-anagrams/49929 "2005-12-10T07:16:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wrong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e19adc/32.png) [@wrong](https://www.ruby-forum.com/u/wrong)\
**Post date:** [December 10, 2005, 7:16am UTC](https://www.ruby-forum.com/t/re-is-this-a-good-way-to-find-anagrams/49929/1 "2005-12-10T07:16:30Z")

</div>

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](mailto:removed_email_address@domain.invalid)  
Date: Friday, December 9, 2005 4:15 am  
Subject: Re: is this a good way to find anagrams?

---

<div class="post-metadata">

**Author:** ![wrong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e19adc/32.png) [@wrong](https://www.ruby-forum.com/u/wrong)\
**Post date:** [December 12, 2005, 9:04am UTC](https://www.ruby-forum.com/t/re-is-this-a-good-way-to-find-anagrams/49929/2 "2005-12-12T09:04:08Z")

</div>

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
