Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def statystyka_slow(n)
- hash = Hash.new
- File.open(n, "r").each_line { |line|
- words = line.downcase.gsub(/[^[:word:]\s]/, '').split
- words.each { |word|
- if hash.has_key?(word)
- hash[word] = hash[word] + 1
- else
- hash[word] = 1
- end
- }
- }
- sum = hash.values.inject(:+)
- hash.each{ |key,value| hash[key] = (value.to_f*100/sum).to_f.round(4)}
- hash.each { |elem|
- puts "\"#{elem[0]}\" = #{elem[1]}%"
- }
- end
- statystyka_slow(gets.chop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement