McNuggets problem: Difference between revisions

Add ABC
(Add MACRO-11)
(Add ABC)
(6 intermediate revisions by 4 users not shown)
Line 77:
{{out}}
<pre>43</pre>
=={{header|ABC}}==
<syntaxhighlight lang="abc">PUT {1..100} IN non.nuggets
 
PUT 0 IN a
WHILE a <= 100:
PUT a IN b
WHILE b <= 100:
PUT b IN c
WHILE c <= 100:
IF c in non.nuggets:
REMOVE c FROM non.nuggets
PUT c+20 IN c
PUT b+9 IN b
PUT a+6 IN a
 
WRITE "Maximum non-McNuggets number:", max non.nuggets/</syntaxhighlight>
{{out}}
<pre>Maximum non-McNuggets number: 43</pre>
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Main()
Line 627 ⟶ 645:
{{out}}
<pre>Maximum non-McNuggets number is: 43</pre>
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">OPTION BASE 0
DIM nuggets(100)
FOR n = 0 TO 100
LET nuggets(n) = 0
NEXT n
 
FOR six = 0 TO 100/6
FOR nine = 0 TO 100/9
FOR twenty = 0 TO 100/20
LET n = six*6 + nine*9 + twenty*20
IF n <= 100 THEN LET nuggets(n) = 1
NEXT twenty
NEXT nine
NEXT six
 
FOR n = 100 TO 1 STEP -1
IF nuggets(n) <> 1 THEN
PRINT "Maximum non-McNuggets number is: "; n
EXIT FOR
END IF
NEXT n
END</syntaxhighlight>
 
==={{header|XBasic}}===
Line 1,734 ⟶ 1,776:
{{out}}
<pre>The largest non-McNuggets number is: 43</pre>
 
=={{header|Pascal}}==
A console program in Free Pascal. Same idea as the Raku solution, but without generalizing. We stop once we've found 6 consecutive integers that can be represented.
<syntaxhighlight lang="pascal">
program McNuggets;
 
{$mode objfpc}{$H+}
 
const
ARRAY_SIZE_STEP = 20; // small, to demonstrate extending array dynamically
var
i, nr_consec : integer;
can_do : array of boolean;
begin
SetLength( can_do, ARRAY_SIZE_STEP);
can_do[0] := true;
nr_consec := 0;
i := 0;
repeat
inc(i);
if i >= Length( can_do) then SetLength( can_do, i + ARRAY_SIZE_STEP);
can_do[i] := ((i >= 6) and can_do[i - 6])
or ((i >= 9) and can_do[i - 9])
or ((i >= 20) and can_do[i - 20]);
if can_do[i] then begin
if can_do[i - 1] then inc( nr_consec)
else nr_consec := 1;
end
else nr_consec := 0;
until nr_consec = 6;
WriteLn ('Max that can''t be represented is ', i - 6);
end.
</syntaxhighlight>
{{out}}
<pre>
Max that can't be represented is 43
</pre>
 
=={{header|Perl}}==
Line 2,376 ⟶ 2,455:
<pre>
Maximum non-McNuggets number is: 43
</pre>
 
=={{header|RPL}}==
{{trans|Go}}
« → limit
« { } limit 1 + + 0 CON
0 limit '''FOR''' s
s limit '''FOR''' n
n limit '''FOR''' t
t 1 + 1 PUT
20 '''STEP'''
9 '''STEP'''
6 '''STEP'''
limit
'''WHILE''' DUP2 GET '''REPEAT''' 1 - '''END'''
1 + SWAP DROP
» » '<span style="color:blue">MCNUGTS</span>' STO
We can tweak a little bit the above traduction, to benefit from latest efficient built-in functions:
{{works with|HP|49}}
« → limit
« 0 limit NDUPN →LIST
0 limit '''FOR''' s
s limit '''FOR''' n
n limit '''FOR''' t
limit t - 1 + 1 PUT
20 '''STEP'''
9 '''STEP'''
6 '''STEP'''
0 POS limit SWAP - 1 +
» » '<span style="color:blue">MCNUGTS</span>' STO
 
100 <span style="color:blue">MCNUGTS</span>
{{out}}
<pre>
1: 43
</pre>
 
Line 2,704 ⟶ 2,818:
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="ecmascriptwren">var mcnugget = Fn.new { |limit|
var sv = List.filled(limit+1, false)
var s = 0
2,093

edits