Advertisement
Guest User

Untitled

a guest
Oct 21st, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. puts "Give me a sentence: "
  3. sentence = gets.chomp
  4.  
  5. words = sentence.split
  6.  
  7. numberoftimes= Hash.new
  8.  
  9. words.each {|word| numberoftimes[word] += 1}
  10. numberoftimes=numberoftimes.sort_by {|word,amount|amount}
  11.  
  12. numberoftimes.each do |word,amount|
  13. puts word + " " + number.to_s
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement