RosettaCodeData/Task/McNuggets-problem/Oberon-07/mcnuggets-problem.oberon
2026-04-30 12:34:36 -04:00

21 lines
858 B
Text

MODULE McNuggetsProblem;
(* 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 *)
IMPORT Out;
CONST maxNuggets = 100;
VAR isSum : ARRAY maxNuggets + 1 OF BOOLEAN;
x, y, z, largest : INTEGER;
BEGIN
(* find the numbers that can be formed *)
FOR x := 0 TO maxNuggets BY 6 DO
FOR y := x TO maxNuggets BY 9 DO
FOR z := y TO maxNuggets BY 20 DO isSum[ z ] := TRUE END
END
END;
(* show the highest number that cannot be formed *)
largest := maxNuggets;
WHILE isSum[ largest ] DO DEC( largest ) END;
Out.String( "The largest non-McNugget number is: " );Out.Int( largest, 0 );Out.Ln
END McNuggetsProblem.