McNuggets problem: Difference between revisions

Add Refal
(added RPL)
(Add Refal)
 
(5 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 2,328 ⟶ 2,370:
Maximum non-Mcnugget number using 2, 4, 6 is: ∞
Maximum non-Mcnugget number using 3, 6, 15 is: ∞</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
, <Iota 0 6 100>: e.A
, <Iota 0 9 100>: e.B
, <Iota 0 20 100>: e.C
, <Iota 0 1 100>: e.Nums
, <SumPairs (e.A) (<SumPairs (e.B) (e.C)>)>: e.Nuggets
, <RemoveAll (e.Nuggets) e.Nums>: e.NonNuggets
, e.NonNuggets: e.X s.Last
= <Prout 'The largest non-McNuggets number < 100 is: ' s.Last>;
};
 
SumPairs {
() (e.Y) = ;
(s.I e.X) (e.Y) = <SumPairs1 s.I (e.Y)> <SumPairs (e.X) (e.Y)>;
};
 
SumPairs1 {
s.I () = ;
s.I (s.X e.X) = <+ s.I s.X> <SumPairs1 s.I (e.X)>;
};
 
Remove {
s.I e.X s.I e.Y = e.X <Remove s.I e.Y>;
s.I e.X = e.X;
};
 
RemoveAll {
() e.X = e.X;
(s.R e.R) e.X = <RemoveAll (e.R) <Remove s.R e.X>>;
};
 
Iota {
s.Start s.Step s.End, <Compare s.Start s.End>: {
'+' = ;
s.X = s.Start <Iota <+ s.Start s.Step> s.Step s.End>;
};
};</syntaxhighlight>
{{out}}
<pre>The largest non-McNuggets number < 100 is: 43</pre>
 
=={{header|REXX}}==
Line 2,415 ⟶ 2,498:
</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
Line 2,426 ⟶ 2,524:
9 '''STEP'''
6 '''STEP'''
ARRY→ 1 GET →LIST
0 POS limit SWAP - 1 +
» » '<span style="color:blue">MCNUGTS</span>' STO
Line 2,435 ⟶ 2,532:
1: 43
</pre>
 
=={{header|Ruby}}==
{{trans|Go}}
Line 2,761 ⟶ 2,859:
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="ecmascriptwren">var mcnugget = Fn.new { |limit|
var sv = List.filled(limit+1, false)
var s = 0
2,095

edits