Shubhadeep Roychowdhury
07/25/2022, 3:27 AMJack Rusher
07/25/2022, 9:01 AMTony Worm
07/25/2022, 7:38 PMJack Rusher
07/26/2022, 6:48 AMwtaysom
07/26/2022, 8:55 AMcounts = Hash.new(0)
STDIN.each_line { |line| line.downcase.split.each { |w| counts[w] += 1 }}
counts.sort_by { |k,v| -v }.each { |k,v| puts "#{k} #{v}" }
old. A quick round of golf:
STDIN.flat_map{_1.downcase.split}.
tally.sort_by{-_2}.
each{puts _1.join(" ")}
It only goes to show that counting things is a common Rubyism.
Games like this always remind me of the The Evolution of a Haskell Programmer https://pages.cpsc.ucalgary.ca/~robin/class/449/Evolution.htm.Tony Worm
07/26/2022, 8:21 PMcat file.txt | wc -w
Tony Worm
07/26/2022, 8:22 PMJack Rusher
07/27/2022, 7:29 AM