Advertisement
kolpastebin

Frequency.rb

Jul 4th, 2014
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. def main(arguments)
  4. word = 'default'
  5. if arguments.length > 0
  6. word = arguments[0]
  7. end
  8.  
  9. hashes = Hash.new(0)
  10. word.each_char { |c| hashes[c] += 1 }
  11.  
  12. sorted_hashes = hashes.sort_by {|k, v| -v}
  13. puts 'Letter frequencies for "' + word +'":'
  14. puts "letter\tcount"
  15. sorted_hashes.each { |entry| puts entry[0] + "\t" + entry[1].to_s }
  16. end
  17.  
  18.  
  19.  
  20. if __FILE__ == $0
  21. main(ARGV)
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement