0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Ruby]簡易ポーカー作ってみました。アドバイスください

Posted at

Ruby で簡易ポーカー(トランプは四枚だけど)を作ってみました。
が、あまりにもわからずに可読性落ちまくりのプログラムになってしまったので
よろしければアドバイスください。

qiita.rb
n = gets.to_i
poker = []
i = 0
check = 0


n.times do
  number = gets.chomp
  poker.push(number.chars)
end


while n > 0 
  check = poker[i].uniq.map{ |e| [e, poker[i].count(e)] }
  case check.size
    when 4 then
      puts "No Pair"
    when 3 then
      puts "One Pair"
    when 2 then
      if check[0][1] == 3
        puts "Three Card"
      else
        puts "Two Pair"
      end
    when 1 then
      puts "Four Card"
    end
    i = i + 1
    n = n - 1
end

ブロック変数の理解が浅いことが悩みです笑

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?