Skip to content

Instantly share code, notes, and snippets.

@torazuka
Last active January 12, 2016 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torazuka/a737b067c00fb0afa97f to your computer and use it in GitHub Desktop.
Save torazuka/a737b067c00fb0afa97f to your computer and use it in GitHub Desktop.
オフラインリアルタイムどう書く#参考問題01 Ruby解答
#!/usr/bin/ruby
def is_fourcards (cs)
return cs.has_value?(4)
end
def is_threecards (cs)
return cs.has_value?(3)
end
def cnt_pairs (cs)
return cs.select {|k,v| v == 2}.length
end
input = ARGV[0]
ws = input.gsub(/10/,"T").split("")
cs = []
ws.each { |w| cs.push(w) unless /S|H|D|C/ =~ w }
nums = { }
(2..9).each { |n|
nums[n.to_s] = 0
}
nums.update({"T" => 0, "J" => 0, "Q" => 0, "K" => 0, "A" => 0})
cs.each { |c|
nums[c] = nums[c] + 1
}
result = "--"
if is_fourcards(nums) then
rsult = "4K"
elsif is_threecards(nums) && cnt_pairs(nums) == 1 then
result = "FH"
elsif is_threecards(nums) then
result = "3K"
elsif cnt_pairs(nums) == 2 then
result = "2P"
elsif cnt_pairs(nums) == 1 then
result = "1P"
end
print result
@torazuka
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment