with javascript_semantics function Mcnugget_number(sequence counts) if gcd(counts)>1 then return "No maximum" end if integer cmin = min(counts), klim = 0, a = -1 sequence meals = {} 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)) if k and (klim=0 or k<=klim) then if k>length(meals) then meals &= repeat(0,k-length(meals)) end if meals[k] = 1 end if end for end for end for integer r = 0, res = 0 for i=1 to length(meals) do if meals[i] then r += 1 if r=cmin then klim = res exit end if else r = 0 res = i end if end for if r=cmin and a*cmin>res then return sprintf("%d",res) end if end while 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}, {12,14,17},{12,13,34},{5,9,21},{10,18,21},{71,98,99},{4,30,16},{12,12,13},{6,15,1}} for t in tests do printf(1,"Maximum non-Mcnugget number using %v is: %s\n",{t,Mcnugget_number(t)}) end for