Skip to content

Instantly share code, notes, and snippets.

@qickstarter
Created August 29, 2012 09:03
Show Gist options
  • Save qickstarter/3508837 to your computer and use it in GitHub Desktop.
Save qickstarter/3508837 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby -w
# 挨拶
greetings = ["おはよう", "おはよう", "こんにちは", "こんばんは", "こんばんは", "おはよう", "こんばんは", "おはよう"]
# 挨拶の回数を数えるハッシュ
count = Hash.new(0)
# 回数を数える
greetings.each {|greeting|
count[greeting] += 1
}
# 回数を表示する
count.each {|greeting, ct|
puts "#{greeting} : #{ct} 回"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment