12/04/22 02:31:25.32
>>514をRubyに翻訳してみた版
stock = ([*1..9]*4).shuffle
player = stock.shift(7)
loop do
choice = nil
loop do
puts player.sort.inspect + "から合計が15になるようにチョイス"
choice = gets.split(/[, ]/).map(&:to_i)
choice.delete(0)
if choice.empty?
puts "ギブアップ?[Y/n]"
!(gets=="n\n") ? exit : choice = [0]
end
break if choice.all?(&:integer?) and
choice.reduce(&:+) == 15 and
choice.uniq.all?{ |card| player.count(card) >= choice.count(card) }
end
choice.each{ |e| player.delete_at(player.index(e)) }
player += stock.shift([choice.size, stock.size].min)
break if player.empty?
end
puts "おめでとう!"