Skip to content

Instantly share code, notes, and snippets.

@Rukomoynikov
Last active April 20, 2016 05:00
Show Gist options
  • Save Rukomoynikov/0f125029a81b8efe8231ad6563fc02f2 to your computer and use it in GitHub Desktop.
Save Rukomoynikov/0f125029a81b8efe8231ad6563fc02f2 to your computer and use it in GitHub Desktop.
# TOP 10 of most frequently words
words = Hash.new(0);
File.foreach('./text.txt') do |line|
line.split(' ').each do |word|
formattedWord = word.gsub(/[\W]/, "").downcase
words[formattedWord] += 1
end
end
words = words.sort_by{ |word| word[1]}.reverse()
File.open("./beauty_of_word.txt", "w") do |io|
counter = 0
words.each do |count, word|
break if counter == 10
counter += 1
io.puts "Слово #{word} встречается #{count} раз"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment