--nextPart2139708.tvCfTPD2iy
Content-Type: text/plain;
  charsetso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hey travis,

you gave me a good time figuring this one out... after some thought i came up 
with something that takes roughly 1 second to search 9,6k words for a 
anagram.
of course this will go up when you add more words (a task you still can think 
about)
all in all, 5 LoC... but i'm sure there are even better ways...

word = "easy".split(//).sort
anagrams = IO.readlines('/usr/share/dict/british-english').partition {|l|
  l.strip!
  (l.size == word.size && l.split(//).sort == word)
}[0]
anagrams.each{|x| puts x}

##### gives you:
manveru@lambda:~/ruby$ time ruby anagramma.rb
ayes
easy
yeas

real    0m1.097s
user    0m0.936s
sys     0m0.105s


Am Donnerstag, 8. Dezember 2005 06:52 schrieb travis laduke:
> it seems to me, with computers these days, this should finish
> instantly, not take like 20 seconds.
> also, please help me make my ruby more ruby-like. i'm new to ruby,
> not that i know any other language.
>
>
> ##these are here from when i was first testing
> secret_word = "spine"
> rack = "spine"
>
> secret_word = secret_word.split(//)
> rack = rack.split(//)
> test_rack = rack.to_s
>
> ##are there enough of the right letters in the rack to spell the word
> from the dictionary?
> ##i think i'm going to use funny spanish names for my methods instead
> of descriptive names.
> def rodolfo(secret_word, rack)
> secret_word.each do |x|
>      rack = rack.to_s
>      if rack.include? x
>          rack = rack.sub(x, '')
>          ##p rack, x
>      else
>          ##puts x, ' rack don\'t work'
>          break
>      end
> end
> end
>
>
> puts "reading dictionary"
> dict = IO.readlines('/usr/share/dict/words')
>
> while rack
>      puts "enter rack"
>      rack = gets.chomp.split(//)
>
>      dict.each do |secret_word|
>
>          if rodolfo(secret_word.chomp.split(//), rack)
>              puts secret_word.to_s
>          end
>      end
> end

--nextPart2139708.tvCfTPD2iy
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBDl+qRMdQeL6eBxhIRAkCdAKDT1Zzg/c7Ihy87ACnbWCsRy+p52QCfWl5M
xD+ZNzI3TItJawMxk2l0k4YI
-----END PGP SIGNATURE-----

--nextPart2139708.tvCfTPD2iy--