McNuggets problem: Difference between revisions

→‎{{header|Perl 6}}: Error trapping
(→‎Using Set Comprehension: Removed personal comment.)
(→‎{{header|Perl 6}}: Error trapping)
Line 535:
=={{header|Perl 6}}==
{{works with|Rakudo|2018.09}}
No hard coded limits, no hard coded values. General purpose 3 value solver. Count values may be any 3 different positive integers, in any order, though if theythat are all even, no maximum non-McNugget number is possible (can't form oddrelatively numbers)prime.
 
Finds the smallest count value, then looks for the first run of consecutive count totals able to be generated, that is at least the length of the smallest count size. From then on, every number can be generated by simply adding multiples of the minimum count to each of the totals in that run.
Line 541:
<lang perl6>sub Mcnugget-number (*@counts) {
 
return 'No maximum' if so1 all< [gcd] @counts »%%» 2;
 
my $min = [min] @counts;
Line 570:
}
 
for (6,9,20), (6,7,20), (1,3,20), (10,5,18), (5,17,44), (2,4,6), (3,6,15) -> $counts {
put "Maximum non-Mcnugget number using {$counts.join: ', '} is: ",
Mcnugget-number(|$counts)
Line 580:
Maximum non-Mcnugget number using 10, 5, 18 is: 67
Maximum non-Mcnugget number using 5, 17, 44 is: 131
Maximum non-Mcnugget number using 2, 4, 6 is: No maximum</pre>
Maximum non-Mcnugget number using 3, 6, 15 is: ∞</pre>
 
=={{header|Python}}==
10,333

edits