RosettaCodeData/Task/McNuggets-problem/Pluto/mcnuggets-problem.pluto
2026-04-30 12:34:36 -04:00

19 lines
626 B
Text

do -- Solve the McNuggets problem find the largest n <= 100 for which there
-- are no non-negative integers x, y, z such that 6x + 9y + 20z = n
local maxNuggets <const> = 100
local sum = {}
for i = 0, maxNuggets do sum[ i ] = false end
for x = 0, maxNuggets, 6 do
for y = x, maxNuggets, 9 do
for z = y, maxNuggets, 20 do
sum[ z ] = true
end
end
end
-- show the highest number that cannot be formed
local largest = maxNuggets
while sum[ largest ] do largest -= 1 end
print( $"The largest non McNugget number is {largest}" )
end