McNuggets problem: Difference between revisions
Content added Content deleted
(This code is functional seems like an important rather than personal comment) |
(Added more generic solution) |
||
Line 852: | Line 852: | ||
43 |
43 |
||
</pre> |
</pre> |
||
Generic solution, allowing for more or less then 3 portion-sizes |
|||
<lang ruby>limit = 100 |
|||
nugget_portions = [6, 9, 20] |
|||
hits = [] |
|||
arrs = nugget_portions.map{|n| 0.step(limit, n).to_a } |
|||
arrs.pop.product(*arrs){|prod| hits << prod.sum } |
|||
p ((0..limit).to_a - hits).max # => 43</lang> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |