Skip to content

Instantly share code, notes, and snippets.

@evdokimovm
Created January 24, 2016 00:45
Show Gist options
  • Save evdokimovm/df74983f3ab1aaac5201 to your computer and use it in GitHub Desktop.
Save evdokimovm/df74983f3ab1aaac5201 to your computer and use it in GitHub Desktop.
Simple Ruby Histogram
puts "Text please: "
text = gets.chomp
words = text.split(" ")
frequencies = Hash.new(0)
words.each { |word| frequencies[word] += 1 }
frequencies = frequencies.sort_by {|a, b| b }
frequencies.reverse!
frequencies.each { |word, frequency| puts word + " " + frequency.to_s }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment