The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
/mnt/cjhttpd/home/cilibrar/stuff/esotericruby/RubyKata/katasix.rb.html

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Rudi Cilibrasi

Posts: 25
Nickname: cilibrar
Registered: Aug, 2004

Rudi Cilibrasi is a longtime programmer and machine-learning researcher who loves Ruby
/mnt/cjhttpd/home/cilibrar/stuff/esotericruby/RubyKata/katasix.rb.html Posted: Nov 20, 2005 3:54 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Rudi Cilibrasi.
Original Post: /mnt/cjhttpd/home/cilibrar/stuff/esotericruby/RubyKata/katasix.rb.html
Feed Title: Esoteric Ruby Blog
Feed URL: http://cilibrar.com/~cilibrar/erblog.cgi/index.rss
Feed Description: A weblog made to explore some Ruby ideas in great detail and try to work out ideal solutions to real problems.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Rudi Cilibrasi
Latest Posts From Esoteric Ruby Blog

Advertisement

Ruby Kata Six -- Anagram

# This was a fun one; another classic algorithm popular in class but always # fun to recreate. This reminds me also of the related Boggle type problem. # Here's my answer for the anagram list. Just feed the list of words to stdin. #!/usr/bin/env ruby def toHistogram(str) res = [ ] str.each_byte { |i| res << i } res.sort end result = STDIN.readlines.inject({}) do |n, w| w.chomp! h = toHistogram(w) n[h] ||= [ ] n[h].push(w) n end goodkeys = result.keys.sort_by { |i| -result[i].size } goodkeys.each { |k| v = result[k] puts v.join(' ') if v.size > 1 }

Read: /mnt/cjhttpd/home/cilibrar/stuff/esotericruby/RubyKata/katasix.rb.html

Topic: Towards more RESTful Rails Previous Topic   Next Topic Topic: Look what my mom made!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use