Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > finding anagram of words

Reply
Thread Tools

finding anagram of words

 
 
Peter Kimani
Guest
Posts: n/a
 
      05-03-2009
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

Attachments:
http://www.ruby-forum.com/attachment/3645/word.txt

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Tim Hunter
Guest
Posts: n/a
 
      05-03-2009
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.

--
RMagick: http://rmagick.rubyforge.org/

 
Reply With Quote
 
 
 
 
Robert Dober
Guest
Posts: n/a
 
      05-03-2009
On Sun, May 3, 2009 at 2:31 AM, Tim Hunter <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: anagram finder / dict mapping question Kam-Hung Soh Python 16 05-11-2008 02:09 AM
Anyone feel like an anagram? Steve B NZ Computing 4 06-09-2006 08:17 AM
Non-noise words are incorrectly recognised as noise words. Peter Strĝiman ASP .Net 1 08-23-2005 01:26 PM
The old anagram problem with open address hashing HS77154 DK15798 C++ 1 07-09-2004 05:31 PM
anagram problem BjoernJackschina C++ 1 05-12-2004 04:10 PM



Advertisments