All pastes #940472 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-03-13 00:08 UTC
rendered paste body
def learn
	$text = text
	words = text.split(/[^a-zA-Z]/)
	freqs = Hash.new(0)
	words.each { |word| freqs[word] += 1 }
end


puts "Teach me something\n\n"
text = gets.chomp
learn

#words = text.split(/[^a-zA-Z]/)
#freqs = Hash.new(0)
#words.each { |word| freqs[word] += 1 }
freqs = freqs.sort_by {|x,y| y }
freqs.reverse!
freqs.each {|word, freq| puts word+' '+freq.to_s}