McNuggets problem: Difference between revisions

(→‎{{header|Perl 6}}: Error trapping)
Line 582:
Maximum non-Mcnugget number using 2, 4, 6 is: ∞
Maximum non-Mcnugget number using 3, 6, 15 is: ∞</pre>
 
=={{header|Phix}}==
{{trans|Go}}
<lang Phix>constant limit=100
sequence nuggets = repeat(false,limit+1)
for sixes=0 to limit by 6 do
for nines=sixes to limit by 9 do
for twenties=nines to limit by 20 do
nuggets[twenties+1] = true
end for
end for
end for
printf(1,"Maximum non-McNuggets number is %d\n", rfind(false,nuggets)-1)</lang>
{{out}}
<pre>
Maximum non-McNuggets number is 43
</pre>
Also, since it is a bit more interesting, a
{{trans|Perl_6}}
<lang Phix>function Mcnugget_number(sequence counts)
if gcd(counts)>1 then return "No maximum" end if
 
atom cmin = min(counts)
sequence meals = {}
sequence smin = {}
integer a = -1
while true do
a += 1
for b=0 to a do
for c=0 to b do
sequence s = {a, b, c}
for i=1 to factorial(3) do
sequence p = permute(i,s)
integer k = sum(sq_mul(p,counts))+1
if k>length(meals) then meals &= repeat(0,k-length(meals)) end if
meals[k] = 1
end for
end for
end for
for i=1 to length(meals) do
if meals[i] then
if length(smin) and smin[$]+1=i-1 then
smin = append(smin,i-1)
if length(smin)=cmin then exit end if
else
smin = {i-1}
end if
end if
end for
if length(smin)=cmin then exit end if
end while
return sprintf("%d",iff(smin[1]?smin[1]-1:0))
end function
constant tests = {{6,9,20}, {6,7,20}, {1,3,20}, {10,5,18}, {5,17,44}, {2,4,6}, {3,6,15}}
for i=1 to length(tests) do
sequence ti = tests[i]
printf(1,"Maximum non-Mcnugget number using %s is: %s\n",{sprint(ti),Mcnugget_number(ti)})
end for</lang>
{{out}}
<pre>
Maximum non-Mcnugget number using {6,9,20} is: 43
Maximum non-Mcnugget number using {6,7,20} is: 29
Maximum non-Mcnugget number using {1,3,20} is: 0
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
Maximum non-Mcnugget number using {3,6,15} is: No maximum
</pre>
 
=={{header|Python}}==
7,820

edits