Created
March 4, 2015 14:41
-
-
Save eiel/ffe292eceb97c9290576 to your computer and use it in GitHub Desktop.
P3なPPM形式の画像の各色の数を数える。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ppmtype = ARGF.readline.chop | |
width, height = *(ARGF.readline.chop.split) | |
max = ARGF.readline | |
hash = Hash.new(0) | |
ARGF.read.split.map(&:to_i).each_slice(3) do |color| | |
hash[color] += 1 | |
end | |
hash.each do |k,v| | |
puts "#{k} #{v}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment