fork(1) download
  1. def f a , score
  2. [1,11].repeated_combination(a).map do |m|
  3. m.sum + score
  4. end.delete_if do|m|
  5. m > 21
  6. end.max
  7. end
  8.  
  9. list = ['A','A',9] # 21
  10. p f(list.count('A'),list.map{|m|m=='A'?0:m}.sum)
  11.  
  12. list = ['A','A',10] # 12
  13. p f(list.count('A'),list.map{|m|m=='A'?0:m}.sum)
Success #stdin #stdout 0.01s 6376KB
stdin
Standard input is empty
stdout
21
12