McNuggets problem: Difference between revisions

Content added Content deleted
m (→‎{{header|Ruby}}: more concise)
Line 856: Line 856:
nugget_portions = [6, 9, 20]
nugget_portions = [6, 9, 20]


hits = []
arrs = nugget_portions.map{|n| 0.step(limit, n).to_a }
arrs = nugget_portions.map{|n| 0.step(limit, n).to_a }
arrs.pop.product(*arrs){|prod| hits << prod.sum }
hits = arrs.pop.product(*arrs).map(&:sum)
p ((0..limit).to_a - hits).max # => 43</lang>
p ((0..limit).to_a - hits).max # => 43</lang>