#!/usr/local/bin/ruby -w
def frequency(text)
def prepare_string(text)
text.gsub!(",", "")
.split(" ")
end
def sort_frequency_report(fq)
fq.to_h
.sort_by{|k, v| v }
.reverse
.to_h
end
word_list = prepare_string(text)
fq = Hash.new()
for word in word_list
if fq.has_key?(word)
fq[word] += 1
else
fq[word] = 1
end
end
sort_frequency_report(fq)
end
p frequency("в этом длинном,
очень и очень длинном тексте
проверим орфографию")
IyEvdXNyL2xvY2FsL2Jpbi9ydWJ5IC13CgpkZWYgZnJlcXVlbmN5KHRleHQpCiAgZGVmIHByZXBhcmVfc3RyaW5nKHRleHQpCiAgICB0ZXh0LmdzdWIhKCIsIiwgIiIpCiAgICAgICAgLnNwbGl0KCIgIikKICBlbmQKCQogIGRlZiBzb3J0X2ZyZXF1ZW5jeV9yZXBvcnQoZnEpCQogICAgZnEudG9faAogICAgICAuc29ydF9ieXt8aywgdnwgdiB9CiAgICAgIC5yZXZlcnNlCiAgICAgIC50b19oCiAgZW5kCgkKICB3b3JkX2xpc3QgPSBwcmVwYXJlX3N0cmluZyh0ZXh0KQogIAogIGZxID0gSGFzaC5uZXcoKQogIAogIGZvciB3b3JkIGluIHdvcmRfbGlzdAogICAgaWYgZnEuaGFzX2tleT8od29yZCkKICAgICAgZnFbd29yZF0gKz0gMQogICAgZWxzZQogICAgICBmcVt3b3JkXSA9IDEKICAgIGVuZCAgCiAgZW5kCiAgCiAgc29ydF9mcmVxdWVuY3lfcmVwb3J0KGZxKQplbmQKCnAgZnJlcXVlbmN5KCLQsiDRjdGC0L7QvCDQtNC70LjQvdC90L7QvCwgCiAgICAgICAgICAgICDQvtGH0LXQvdGMINC4INC+0YfQtdC90Ywg0LTQu9C40L3QvdC+0Lwg0YLQtdC60YHRgtC1IAogICAgICAgICAgICAg0L/RgNC+0LLQtdGA0LjQvCDQvtGA0YTQvtCz0YDQsNGE0LjRjiIpCg==