Forum: Ruby finding anagram of words

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.
Peter k. (Guest)
on 2009-05-03 04:26
Attachment: word.txt (0 Bytes)
Hey,
Please help me to solve this problem with an example. Thanks in advance.
Find anagrams of words e.g. rinse, reins, siren, resin are all anagrams
one of another.

use this file of words (you can use any words)
We will create a signature for a word by spltting it into an array of
letters, sorting that array, and joining the letters back into a string.

So the rinse examples all have signature 'einrs'

My suggested order of operations is:

define a method signature, which returns a signature string.
Hints: chomp, String.split(''), Array.join, Array.sort

Test the method on the rinse examples.


Create a hash, whose key is to be the signature and whose value is an
array of the strings with that signature.
Hint anagrams = Hash.new{ |hash, key| hash[key] = Array.new}

Test that this works on a short example


For each word in the file, create its signature, and append the word to
the array that is the value associated with signature.
Hint: anagrams[signature], <<

Report the value arrays containing 4 or more words.
Hint: Hash.each_value
Tim H. (Guest)
on 2009-05-03 04:31
(Received via mailing list)
Peter Kimani wrote:
> Hey,
> Please help me to solve this problem with an example. Thanks in advance.

This sure sounds like homework. Generally, asking for help about
homework is frowned a little bit by list members, more by homework
givers who are almost certainly list members as well.
Robert D. (Guest)
on 2009-05-03 10:30
(Received via mailing list)
On Sun, May 3, 2009 at 2:31 AM, Tim H. <removed_email_address@domain.invalid> 
wrote:
> Peter Kimani wrote:
>
> This sure sounds like homework. Generally, asking for help about homework is
> frowned a little bit by list members, more by homework givers who are almost
> certainly list members as well.
And if I had been such a homework giver I would give extra negative
credit for not removing the hints.
R.
This topic is locked and can not be replied to.