Advertisement
cd62131

Words

Aug 5th, 2014
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.39 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. require 'open-uri'
  3. words = open('http://history.eserver.org/soviet-diary.txt').read
  4.   .scan(/(?:[a-zA-Z]+(?:['-][a-zA-Z]+)*|[A-Z]\.(?:[A-Z]\.)*)/).lazy
  5.  .map(&:downcase).with_object({}) {|e, h| h[e] ||= 0; h[e] += 1}
  6.  .to_a.sort_by {|(w, c)| [c, w]}.reverse
  7. top10 = words.take 10
  8. rest = words.drop 10
  9. top10.each {|(w, c)| puts "#{w}: #{c}"}
  10. puts "Rest: #{rest.size} words"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement