McNuggets problem: Difference between revisions
Content added Content deleted
(Added Asymptote) |
(Added various BASIC dialects) |
||
Line 404: | Line 404: | ||
{{out}} |
{{out}} |
||
<pre> 43</pre> |
<pre> 43</pre> |
||
==={{header|Applesoft BASIC}}=== |
|||
{{works with|Chipmunk Basic|3.6.4}} |
|||
<syntaxhighlight lang="qbasic">100 dim nuggets(100) |
|||
110 for six = 0 to 100/6 |
|||
120 for nine = 0 to 100/9 |
|||
130 for twenty = 0 to 100/20 |
|||
140 n = six*6+nine*9+twenty*20 |
|||
150 if n <= 100 then nuggets(n) = 1 |
|||
160 next twenty |
|||
170 next nine |
|||
180 next six |
|||
190 for n = 100 to 1 step -1 |
|||
200 if nuggets(n) <> 1 then print "Maximum non-McNuggets number is: ";n : goto 250 |
|||
240 next n |
|||
250 end</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Maximum non-McNuggets number is: 43</pre> |
|||
==={{header|BASIC256}}=== |
|||
<syntaxhighlight lang="vb">arraybase 1 |
|||
dim nuggets(100) |
|||
for six = 0 To 100/6 |
|||
for nine = 0 To 100/9 |
|||
for twenty = 0 To 100/20 |
|||
n = six*6 + nine*9 + twenty*20 |
|||
if n <= 100 then nuggets[n] = true |
|||
next twenty |
|||
next nine |
|||
next six |
|||
for n = 100 to 1 step -1 |
|||
if nuggets[n] = false then |
|||
print "Maximum non-McNuggets number is: "; n |
|||
exit for |
|||
end if |
|||
next n</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Maximum non-McNuggets number is: 43</pre> |
|||
==={{header|Chipmunk Basic}}=== |
|||
{{works with|Chipmunk Basic|3.6.4}} |
|||
<syntaxhighlight lang="qbasic">100 dim nuggets(100) |
|||
110 for six = 0 to 100/6 |
|||
120 for nine = 0 to 100/9 |
|||
130 for twenty = 0 to 100/20 |
|||
140 n = six*6+nine*9+twenty*20 |
|||
150 if n <= 100 then nuggets(n) = 1 |
|||
160 next twenty |
|||
170 next nine |
|||
180 next six |
|||
190 for n = 100 to 1 step -1 |
|||
200 if nuggets(n) <> 1 then |
|||
210 print "Maximum non-McNuggets number is: ";n |
|||
220 end |
|||
230 endif |
|||
240 next n |
|||
250 end</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Maximum non-McNuggets number is: 43</pre> |
|||
==={{header|GW-BASIC}}=== |
|||
The [[#Chipmunk Basic|Chipmunk Basic]] solution works without any changes. |
|||
==={{header|Minimal BASIC}}=== |
|||
{{works with|QBasic}} |
|||
{{works with|QuickBasic}} |
|||
{{works with|Applesoft BASIC}} |
|||
{{works with|BASICA}} |
|||
{{works with|Chipmunk Basic}} |
|||
{{works with|GW-BASIC}} |
|||
{{works with|MSX BASIC}} |
|||
{{works with|Quite BASIC}} |
|||
<syntaxhighlight lang="qbasic">10 DIM N(100) : rem 10 ARRAY N for Quite BASIC |
|||
20 FOR A = 0 TO 100/6 |
|||
30 FOR B = 0 TO 100/9 |
|||
40 FOR C = 0 TO 100/20 |
|||
50 LET K = A*6+B*9+C*20 |
|||
60 IF K <= 100 THEN 80 |
|||
70 GOTO 90 |
|||
80 LET N(K) = 1 |
|||
90 NEXT C |
|||
100 NEXT B |
|||
110 NEXT A |
|||
120 FOR K = 100 TO 1 STEP -1 |
|||
130 IF N(K) <> 1 THEN 160 |
|||
140 NEXT K |
|||
150 STOP |
|||
160 PRINT "Maximum non-McNuggets number is: "; K |
|||
170 END</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Maximum non-McNuggets number is: 43</pre> |
|||
==={{header|MSX Basic}}=== |
|||
{{works with|MSX BASIC|any}} |
|||
The [[#Minimal BASIC|Minimal BASIC]] solution works without any changes. |
|||
==={{header|PureBasic}}=== |
|||
<syntaxhighlight lang="purebasic">OpenConsole() |
|||
Define n.i |
|||
Dim nuggets.i(100) |
|||
For six.i = 0 To 100/6 |
|||
For nine.i = 0 To 100/9 |
|||
For twenty.i = 0 To 100/20 |
|||
n = six*6 + nine*9 + twenty*20 |
|||
If n <= 100 |
|||
nuggets(n) = #True |
|||
EndIf |
|||
Next twenty |
|||
Next nine |
|||
Next six |
|||
For n = 100 To 1 Step -1 |
|||
If nuggets(n) = #False |
|||
PrintN("Maximum non-McNuggets number is: " + Str(n)) |
|||
Break |
|||
EndIf |
|||
Next n |
|||
PrintN(#CRLF$ + "Press ENTER to exit"): Input() |
|||
CloseConsole()</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Maximum non-McNuggets number is: 43</pre> |
|||
==={{header|Quite BASIC}}=== |
|||
The [[#Minimal BASIC|Minimal BASIC]] solution works without any changes. |
|||
==={{header|Run BASIC}}=== |
|||
{{works with|Just BASIC}} |
|||
{{works with|Liberty BASIC}} |
|||
<syntaxhighlight lang="vb">dim nuggets(100) |
|||
for six = 0 to 100/6 |
|||
for nine = 0 to 100/9 |
|||
for twenty = 0 to 100/20 |
|||
n = six*6 + nine*9 + twenty*20 |
|||
if n <= 100 then 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 |
|||
end |
|||
end if |
|||
next n</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Maximum non-McNuggets number is: 43</pre> |
|||
==={{header|XBasic}}=== |
|||
{{works with|Windows XBasic}} |
|||
<syntaxhighlight lang="qbasic">PROGRAM "McNuggets problem" |
|||
VERSION "0.0000" |
|||
DECLARE FUNCTION Entry () |
|||
FUNCTION Entry () |
|||
DIM N[100] |
|||
FOR A = 0 TO 100/6 |
|||
FOR B = 0 TO 100/9 |
|||
FOR C = 0 TO 100/20 |
|||
K = A*6+B*9+C*20 |
|||
IF K <= 100 THEN N[K] = 1 |
|||
NEXT C |
|||
NEXT B |
|||
NEXT A |
|||
FOR K = 100 TO 1 STEP -1 |
|||
IF N[K] <> 1 THEN PRINT "Maximum non-McNuggets number is: "; K : EXIT FOR |
|||
NEXT K |
|||
END FUNCTION |
|||
END PROGRAM</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Maximum non-McNuggets number is: 43</pre> |
|||
==={{header|Yabasic}}=== |
|||
<syntaxhighlight lang="vb">dim nuggets(100) |
|||
for six = 0 to 100/6 |
|||
for nine = 0 to 100/9 |
|||
for twenty = 0 to 100/20 |
|||
n = six*6 + nine*9 + twenty*20 |
|||
if n <= 100 nuggets(n) = true |
|||
next twenty |
|||
next nine |
|||
next six |
|||
for n = 100 to 1 step -1 |
|||
if nuggets(n) = false then |
|||
print "Maximum non-McNuggets number is: ", n |
|||
break |
|||
end if |
|||
next n</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Maximum non-McNuggets number is: 43</pre> |
|||
=={{header|BCPL}}== |
=={{header|BCPL}}== |