McNuggets problem: Difference between revisions

Add ABC
(Added Easylang)
(Add ABC)
(10 intermediate revisions by 6 users not shown)
Line 31:
</pre>
 
=={{header|8080 Assembly}}==
<syntaxhighlight lang="asm"> org 100h
lxi h,200h ; Zero out a page to keep nugget flags
xra a
znugs: mov m,a
inr l
jnz znugs
lxi b,101 ; B = 6 stepper, C = 101 (limit)
loopa: mov d,b ; D = 9 stepper
loopb: mov l,d ; L = 20 stepper
loopc: inr m ; Mark nugget
mvi a,20 ; 20 step
add l
mov l,a
cmp c
jc loopc
mvi a,9 ; 9 step
add d
mov d,a
cmp c
jc loopb
mvi a,6 ; 6 step
add b
mov b,a
cmp c
jc loopa
mov l,c ; Find largest number not seen
scan: dcr l
dcr m
jp scan
mov a,l
mvi b,'0'-1 ; B = high digit
digit: inr b
sui 10
jnc digit
adi '0'+10 ; A = low digit
lxi h,digits+1
mov m,a ; Store digits
dcx h
mov m,b
xchg
mvi c,9 ; CP/M print string
jmp 5
digits: db 0,0,'$' ; Placeholder for output</syntaxhighlight>
{{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 463 ⟶ 527:
240 next n
250 end</syntaxhighlight>
{{out}}
<pre>Maximum non-McNuggets number is: 43</pre>
 
==={{header|Gambas}}===
<syntaxhighlight lang="vbnet">Public l[101] As Integer
 
Public Sub Main()
Dim a As Integer, b As Integer, c As Integer, n As Integer
For a = 0 To 100 / 6
For b = 0 To 100 / 9
For c = 0 To 100 / 20
n = a * 6 + b * 9 + c * 20
If n <= 100 Then l[n] = True
Next
Next
Next
For n = 100 To 1 Step -1
If Not l[n] Then
Print "Maximum non-McNuggets number is: "; n
Break
End If
Next
End</syntaxhighlight>
{{out}}
<pre>Maximum non-McNuggets number is: 43</pre>
Line 555 ⟶ 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,515 ⟶ 1,629:
43
</pre>
 
=={{header|MACRO-11}}==
<syntaxhighlight lang="macro11"> .TITLE NUGGET
.MCALL .TTYOUT,.EXIT
NUGGET::MOV #^D50,R1
MOV #NUGBUF,R0
CLEAR: CLR (R0)+ ; CLEAR BUFFER
SOB R1,CLEAR
MARK: MOV #^D100,R5 ; R5 = LIMIT
CLR R0 ; R0 = 6 STEPPER
1$: MOV R0,R1 ; R1 = 9 STEPPER
2$: MOV R1,R2 ; R2 = 20 STEPPER
3$: INCB NUGBUF(R2) ; MARK
ADD #^D20,R2 ; 20 STEP
CMP R2,R5
BLT 3$
ADD #^D9,R1 ; 9 STEP
CMP R1,R5
BLT 2$
ADD #^D6,R0 ; 6 STEP
CMP R0,R5
BLT 1$
SCAN: MOV #NUGBUF+^D100,R0
1$: DEC R5
MOVB -(R0),R1
BNE 1$
DIGIT: MOV #'0-1,R0 ; SPLIT DIGITS
1$: INC R0
SUB #^D10,R5
BCC 1$
.TTYOUT ; HIGH DIGIT
MOV R5,R0
ADD #'0+^D10,R0
.TTYOUT ; LOW DIGIT
.EXIT
NUGBUF: .BLKB ^D100
.END NUGGET</syntaxhighlight>
{{out}}
<pre>43</pre>
 
=={{header|MAD}}==
Line 1,571 ⟶ 1,724:
{{out}}
<pre>Maximum non-McNuggets number: 43</pre>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
n = range(0, 100)
for six in range(0, 100, 6)
for nine in range(0, 100, 9)
for twenty in range(0, 100, 20)
mcnuggets = six + nine + twenty
ix = n.indexOf(mcnuggets)
if ix != null then n.remove(ix)
end for
end for
end for
 
print "The largest non-McNugget number is " + n[-1]
</syntaxhighlight>
{{out}}
<pre>
The largest non-McNugget number is 43</pre>
 
=={{header|MiniZinc}}==
Line 1,604 ⟶ 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,246 ⟶ 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,574 ⟶ 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