Blackjack_2

Summing of hand. Link to heading

# if the hand comes as an Array (where J Q K is transformed to 10)

ar.partition { it == :A }.then {|a,b|
  a.inject(b.sum) {|acc, obj| acc + (acc + 11 > 21 ? 1 : 11) }
}.then {|tot| p (tot > 21 ? 'BUST' : tot) }

# another try.. we have an array of values.. ace is represented by 11

ar = [7,11,2,11]

p [ar.sum, ar.count(11)].then {|s, a| a.times { s -= 10 if s > 21 }; s }