McNuggets problem: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 18: Line 18:
{{trans|Python}}
{{trans|Python}}


<lang 11l>V nuggets = Set(0..100)
<syntaxhighlight lang="11l">V nuggets = Set(0..100)
L(s, n, t) cart_product(0 .. 100 I/ 6,
L(s, n, t) cart_product(0 .. 100 I/ 6,
0 .. 100 I/ 9,
0 .. 100 I/ 9,
Line 24: Line 24:
nuggets.discard(6*s + 9*n + 20*t)
nuggets.discard(6*s + 9*n + 20*t)


print(max(nuggets))</lang>
print(max(nuggets))</syntaxhighlight>


{{out}}
{{out}}
Line 32: Line 32:


=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>PROC Main()
<syntaxhighlight lang="action!">PROC Main()
BYTE x,y,z,n
BYTE x,y,z,n
BYTE ARRAY nuggets(101)
BYTE ARRAY nuggets(101)
Line 67: Line 67:
FI
FI
OD
OD
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/McNuggets_problem.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/McNuggets_problem.png Screenshot from Atari 8-bit computer]
Line 75: Line 75:


=={{header|Ada}}==
=={{header|Ada}}==
<lang Ada>with Ada.Text_IO; use Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;


procedure McNugget is
procedure McNugget is
Line 98: Line 98:
end if;
end if;
end loop;
end loop;
end McNugget;</lang>
end McNugget;</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 105: Line 105:


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<lang algol68>BEGIN
<syntaxhighlight lang="algol68">BEGIN
# Solve the McNuggets problem: find the largest n <= 100 for which there #
# 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 #
# are no non-negative integers x, y, z such that 6x + 9y + 20z = n #
Line 126: Line 126:
)
)
)
)
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 134: Line 134:
=={{header|APL}}==
=={{header|APL}}==
{{works with|Dyalog APL}}
{{works with|Dyalog APL}}
<lang APL>100 (⌈/(⍳⊣)~(⊂⊢)(+/×)¨(,⎕IO-⍨(⍳∘⌊÷))) 6 9 20</lang>
<syntaxhighlight lang="apl">100 (⌈/(⍳⊣)~(⊂⊢)(+/×)¨(,⎕IO-⍨(⍳∘⌊÷))) 6 9 20</syntaxhighlight>
{{out}}
{{out}}
<pre>43</pre>
<pre>43</pre>
Line 141: Line 141:
Generalised for other set sizes, and for other triples of natural numbers.
Generalised for other set sizes, and for other triples of natural numbers.
Uses NSMutableSet, through the AppleScript ObjC interface:
Uses NSMutableSet, through the AppleScript ObjC interface:
<lang applescript>use AppleScript version "2.4"
<syntaxhighlight lang="applescript">use AppleScript version "2.4"
use framework "Foundation"
use framework "Foundation"
use scripting additions
use scripting additions
Line 317: Line 317:
on setMember(x, objcSet)
on setMember(x, objcSet)
missing value is not (objcSet's member:(x))
missing value is not (objcSet's member:(x))
end setMember</lang>
end setMember</syntaxhighlight>
{{Out}}
{{Out}}
<pre>43</pre>
<pre>43</pre>
Line 323: Line 323:
=={{header|Arturo}}==
=={{header|Arturo}}==
{{trans|Ruby}}
{{trans|Ruby}}
<lang rebol>nonMcNuggets: function [lim][
<syntaxhighlight lang="rebol">nonMcNuggets: function [lim][
result: new 0..lim
result: new 0..lim


Line 336: Line 336:
]
]


print max nonMcNuggets 100</lang>
print max nonMcNuggets 100</syntaxhighlight>


{{out}}
{{out}}
Line 343: Line 343:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f MCNUGGETS_PROBLEM.AWK
# syntax: GAWK -f MCNUGGETS_PROBLEM.AWK
# converted from Go
# converted from Go
Line 363: Line 363:
exit(0)
exit(0)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 370: Line 370:


=={{header|BASIC}}==
=={{header|BASIC}}==
<lang basic>10 DEFINT A-Z: DIM F(100)
<syntaxhighlight lang="basic">10 DEFINT A-Z: DIM F(100)
20 FOR A=0 TO 100 STEP 6
20 FOR A=0 TO 100 STEP 6
30 FOR B=A TO 100 STEP 9
30 FOR B=A TO 100 STEP 9
Line 378: Line 378:
70 FOR A=100 TO 0 STEP -1
70 FOR A=100 TO 0 STEP -1
80 IF NOT F(A) THEN PRINT A: END
80 IF NOT F(A) THEN PRINT A: END
90 NEXT A</lang>
90 NEXT A</syntaxhighlight>
{{out}}
{{out}}
<pre> 43</pre>
<pre> 43</pre>


=={{header|BCPL}}==
=={{header|BCPL}}==
<lang bcpl>get "libhdr"
<syntaxhighlight lang="bcpl">get "libhdr"
manifest $( limit = 100 $)
manifest $( limit = 100 $)


Line 400: Line 400:
finish
finish
$)
$)
$)</lang>
$)</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number: 43.</pre>
<pre>Maximum non-McNuggets number: 43.</pre>


=={{header|BQN}}==
=={{header|BQN}}==
<lang bqn>100 ((↕⊣)(⌈´⊣×⊣¬∘∊⥊∘⊢)(<⊢)(+´×)¨(↕⌊∘÷)) 6‿9‿20</lang>
<syntaxhighlight lang="bqn">100 ((↕⊣)(⌈´⊣×⊣¬∘∊⥊∘⊢)(<⊢)(+´×)¨(↕⌊∘÷)) 6‿9‿20</syntaxhighlight>
{{out}}
{{out}}
<pre>43</pre>
<pre>43</pre>
Line 411: Line 411:
=={{header|C}}==
=={{header|C}}==


<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>


int
int
Line 445: Line 445:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 453: Line 453:


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<syntaxhighlight lang="c#">
<lang c#>
using System;
using System;


Line 487: Line 487:
}
}
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 494: Line 494:


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(defn cart [colls]
<syntaxhighlight lang="clojure">(defn cart [colls]
(if (empty? colls)
(if (empty? colls)
'(())
'(())
Line 505: Line 505:
(let [possible (distinct (map nuggets (cart (map range [18 13 6]))))
(let [possible (distinct (map nuggets (cart (map range [18 13 6]))))
mcmax (apply max (filter (fn [x] (not-any? #{x} possible)) (range 101)))]
mcmax (apply max (filter (fn [x] (not-any? #{x} possible)) (range 101)))]
(printf "Maximum non-McNuggets number is %d\n" mcmax))</lang>
(printf "Maximum non-McNuggets number is %d\n" mcmax))</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number is 43</pre>
<pre>Maximum non-McNuggets number is 43</pre>


=={{header|CLU}}==
=={{header|CLU}}==
<lang clu>% Recursive nugget iterator.
<syntaxhighlight lang="clu">% Recursive nugget iterator.
% This yields all the nugget numbers of the given box sizes from start to max.
% This yields all the nugget numbers of the given box sizes from start to max.
gen_nuggets = iter (start, max: int, sizes: sequence[int]) yields (int)
gen_nuggets = iter (start, max: int, sizes: sequence[int]) yields (int)
Line 541: Line 541:
stream$putl(po, "Maximum non-McNuggets number: " || int$unparse(maxn))
stream$putl(po, "Maximum non-McNuggets number: " || int$unparse(maxn))
end start_up</lang>
end start_up</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number: 43</pre>
<pre>Maximum non-McNuggets number: 43</pre>


=={{header|COBOL}}==
=={{header|COBOL}}==
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. MCNUGGETS.
PROGRAM-ID. MCNUGGETS.


Line 580: Line 580:
C-LOOP.
C-LOOP.
IF C IS NOT EQUAL TO ZERO, MOVE 'X' TO NUGGET-FLAGS(C).</lang>
IF C IS NOT EQUAL TO ZERO, MOVE 'X' TO NUGGET-FLAGS(C).</syntaxhighlight>
{{out}}
{{out}}
<pre>Largest non-McNugget number: 043</pre>
<pre>Largest non-McNugget number: 043</pre>


=={{header|Comal}}==
=={{header|Comal}}==
<lang comal>0010 limit#:=100
<syntaxhighlight lang="comal">0010 limit#:=100
0020 DIM nugget#(0:limit#)
0020 DIM nugget#(0:limit#)
0030 FOR a#:=0 TO limit# STEP 6 DO
0030 FOR a#:=0 TO limit# STEP 6 DO
Line 597: Line 597:
0110 END
0110 END
0120 ENDIF
0120 ENDIF
0130 ENDFOR i#</lang>
0130 ENDFOR i#</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number: 43</pre>
<pre>Maximum non-McNuggets number: 43</pre>


=={{header|Cowgol}}==
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
<syntaxhighlight lang="cowgol">include "cowgol.coh";
const LIMIT := 100;
const LIMIT := 100;


Line 635: Line 635:
end if;
end if;
a := a - 1;
a := a - 1;
end loop;</lang>
end loop;</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number: 43</pre>
<pre>Maximum non-McNuggets number: 43</pre>


=={{header|Dart}}==
=={{header|Dart}}==
<lang dart>import 'dart:math';
<syntaxhighlight lang="dart">import 'dart:math';
main() {
main() {
var nuggets = List<int>.generate(101, (int index) => index);
var nuggets = List<int>.generate(101, (int index) => index);
Line 651: Line 651:
}
}
print('Largest non-McNuggets number: ${nuggets.reduce(max).toString() ?? 'none'}.');
print('Largest non-McNuggets number: ${nuggets.reduce(max).toString() ?? 'none'}.');
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 658: Line 658:


=={{header|Draco}}==
=={{header|Draco}}==
<lang draco>proc nonrec main() void:
<syntaxhighlight lang="draco">proc nonrec main() void:
byte LIMIT = 100;
byte LIMIT = 100;
[LIMIT+1] bool nugget;
[LIMIT+1] bool nugget;
Line 678: Line 678:
while nugget[a] do a := a - 1 od;
while nugget[a] do a := a - 1 od;
writeln("Maximum non-McNuggets number: ", a)
writeln("Maximum non-McNuggets number: ", a)
corp</lang>
corp</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number: 43</pre>
<pre>Maximum non-McNuggets number: 43</pre>
Line 686: Line 686:
{{trans|Go}}
{{trans|Go}}


<lang dyalect>func mcnugget(limit) {
<syntaxhighlight lang="dyalect">func mcnugget(limit) {
var sv = Array.Empty(limit + 1, false)
var sv = Array.Empty(limit + 1, false)
for s in 0^6..limit {
for s in 0^6..limit {
Line 703: Line 703:
}
}
mcnugget(100)</lang>
mcnugget(100)</syntaxhighlight>


{{out}}
{{out}}
Line 713: Line 713:
Uses MapSet and Comprehension
Uses MapSet and Comprehension


<lang Elixir>defmodule Mcnugget do
<syntaxhighlight lang="elixir">defmodule Mcnugget do
def solve(limit) do
def solve(limit) do
0..limit
0..limit
Line 735: Line 735:


Mcnugget.solve(100) |> IO.puts
Mcnugget.solve(100) |> IO.puts
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 742: Line 742:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>
<syntaxhighlight lang="fsharp">
// McNuggets. Nigel Galloway: October 28th., 2018
// McNuggets. Nigel Galloway: October 28th., 2018
let fN n g = Seq.initInfinite(fun ng->ng*n+g)|>Seq.takeWhile(fun n->n<=100)
let fN n g = Seq.initInfinite(fun ng->ng*n+g)|>Seq.takeWhile(fun n->n<=100)
printfn "%d" (Set.maxElement(Set.difference (set[1..100]) (fN 20 0|>Seq.collect(fun n->fN 9 n)|>Seq.collect(fun n->fN 6 n)|>Set.ofSeq)))
printfn "%d" (Set.maxElement(Set.difference (set[1..100]) (fN 20 0|>Seq.collect(fun n->fN 9 n)|>Seq.collect(fun n->fN 6 n)|>Set.ofSeq)))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 753: Line 753:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: backtrack kernel math.ranges prettyprint sequences sets ;
<syntaxhighlight lang="factor">USING: backtrack kernel math.ranges prettyprint sequences sets ;
101 <iota> [ 0 6 9 20 [ 100 swap <range> amb-lazy ] tri@ ] bag-of diff last .</lang>
101 <iota> [ 0 6 9 20 [ 100 swap <range> amb-lazy ] tri@ ] bag-of diff last .</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 761: Line 761:


=={{header|FOCAL}}==
=={{header|FOCAL}}==
<lang focal>01.10 F N=0,100;S T(N)=0
<syntaxhighlight lang="focal">01.10 F N=0,100;S T(N)=0
01.20 F A=0,6,100;F B=A,9,100;F C=B,20,100;S T(C)=-1
01.20 F A=0,6,100;F B=A,9,100;F C=B,20,100;S T(C)=-1
01.30 S N=101
01.30 S N=101
Line 767: Line 767:
01.50 I (T(N))1.4
01.50 I (T(N))1.4
01.60 T %3,N,!
01.60 T %3,N,!
01.70 Q</lang>
01.70 Q</syntaxhighlight>
{{out}}
{{out}}
<pre>= 43</pre>
<pre>= 43</pre>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>
<syntaxhighlight lang="freebasic">
Dim As Integer l(100), a, b, c, n
Dim As Integer l(100), a, b, c, n
For a = 0 To 100/6
For a = 0 To 100/6
Line 786: Line 786:
Next n
Next n
End
End
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 794: Line 794:
=={{header|Frink}}==
=={{header|Frink}}==
This is a nice demonstration for Frink's <CODE>multifor</CODE> loop which can perform arbitrarily-deeply-nested loops in a single statement. The "inner" (rightmost) loops can use values set by the "outer" (leftmost) as part of their bounds.
This is a nice demonstration for Frink's <CODE>multifor</CODE> loop which can perform arbitrarily-deeply-nested loops in a single statement. The "inner" (rightmost) loops can use values set by the "outer" (leftmost) as part of their bounds.
<lang frink>a = toSet[0 to 100]
<syntaxhighlight lang="frink">a = toSet[0 to 100]


multifor [z,y,x] = [0 to 100 step 20, 0 to 100-z step 9, 0 to 100-z-y step 6]
multifor [z,y,x] = [0 to 100 step 20, 0 to 100-z step 9, 0 to 100-z-y step 6]
a.remove[x+y+z]
a.remove[x+y+z]


println[max[a]]</lang>
println[max[a]]</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 806: Line 806:


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
<lang futurebasic>
<syntaxhighlight lang="futurebasic">
local fn McNuggetsProblem
local fn McNuggetsProblem
BOOL l(100)
BOOL l(100)
Line 828: Line 828:


HandleEvents
HandleEvents
</syntaxhighlight>
</lang>
{{output}}
{{output}}
<pre>
<pre>
Line 842: Line 842:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 865: Line 865:
func main() {
func main() {
mcnugget(100)
mcnugget(100)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 873: Line 873:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Data.Set (Set, fromList, member)
<syntaxhighlight lang="haskell">import Data.Set (Set, fromList, member)


------------------------ MCNUGGETS -----------------------
------------------------ MCNUGGETS -----------------------
Line 899: Line 899:
where
where
go (x : _) = show x
go (x : _) = show x
go [] = "No unreachable quantities found ..."</lang>
go [] = "No unreachable quantities found ..."</syntaxhighlight>


Or equivalently, making use of the list comprehension notation:
Or equivalently, making use of the list comprehension notation:
<lang haskell>import Data.Set (Set, fromList, member)
<syntaxhighlight lang="haskell">import Data.Set (Set, fromList, member)


gaps :: [Int]
gaps :: [Int]
Line 923: Line 923:
case gaps of
case gaps of
x:_ -> show x
x:_ -> show x
[] -> "No unreachable quantities found ..."</lang>
[] -> "No unreachable quantities found ..."</syntaxhighlight>
<pre>43</pre>
<pre>43</pre>


Line 930: Line 930:
Brute force solution: calculate all pure (just one kind of box) McNugget numbers which do not exceed 100, then compute all possible sums, and then remove those from the list of numbers up to 100 (which is obviously a McNugget number), then find the largest number remaining:
Brute force solution: calculate all pure (just one kind of box) McNugget numbers which do not exceed 100, then compute all possible sums, and then remove those from the list of numbers up to 100 (which is obviously a McNugget number), then find the largest number remaining:


<lang J> >./(i.100)-.,+/&>{(* i.@>.@%~&101)&.>6 9 20
<syntaxhighlight lang="j"> >./(i.100)-.,+/&>{(* i.@>.@%~&101)&.>6 9 20
43</lang>
43</syntaxhighlight>


Technically, we could have used 100 in place of 101 when we were finding how many pure McNugget numbers were in each series (because 100 is obviously a McNugget number), but it's not like that's a problem, either.
Technically, we could have used 100 in place of 101 when we were finding how many pure McNugget numbers were in each series (because 100 is obviously a McNugget number), but it's not like that's a problem, either.


=={{header|Java}}==
=={{header|Java}}==
<lang Java>public class McNuggets {
<syntaxhighlight lang="java">public class McNuggets {


public static void main(String... args) {
public static void main(String... args) {
Line 990: Line 990:
return;
return;
}
}
}</lang>
}</syntaxhighlight>
{{Out}}
{{Out}}
<pre>Largest non-McNugget number in the search space is 43</pre>
<pre>Largest non-McNugget number in the search space is 43</pre>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
<lang javascript>(() => {
<syntaxhighlight lang="javascript">(() => {
'use strict';
'use strict';


Line 1,074: Line 1,074:
main()
main()
);
);
})();</lang>
})();</syntaxhighlight>
{{Out}}
{{Out}}
<pre>43</pre>
<pre>43</pre>
Line 1,080: Line 1,080:
=={{header|jq}}==
=={{header|jq}}==
{{trans|Clojure}}
{{trans|Clojure}}
<lang jq>[
<syntaxhighlight lang="jq">[
[range(18) as $n6 |
[range(18) as $n6 |
range(13) as $n9 |
range(13) as $n9 |
Line 1,091: Line 1,091:
select($possible|contains([$n])|not)
select($possible|contains([$n])|not)
] |
] |
max</lang>
max</syntaxhighlight>
{{out}}
{{out}}
<pre>43</pre>
<pre>43</pre>
Line 1,097: Line 1,097:
=={{header|Julia}}==
=={{header|Julia}}==
Simple brute force solution, though the BitSet would save memory considerably with larger max numbers.
Simple brute force solution, though the BitSet would save memory considerably with larger max numbers.
<lang julia>function mcnuggets(max)
<syntaxhighlight lang="julia">function mcnuggets(max)
b = BitSet(1:max)
b = BitSet(1:max)
for i in 0:6:max, j in 0:9:max, k in 0:20:max
for i in 0:6:max, j in 0:9:max, k in 0:20:max
Line 1,106: Line 1,106:


println(mcnuggets(100))
println(mcnuggets(100))
</lang> {{output}} <pre>
</syntaxhighlight> {{output}} <pre>
43
43
</pre>
</pre>
Line 1,112: Line 1,112:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Go}}
{{trans|Go}}
<lang scala>// Version 1.2.71
<syntaxhighlight lang="scala">// Version 1.2.71


fun mcnugget(limit: Int) {
fun mcnugget(limit: Int) {
Line 1,130: Line 1,130:
fun main(args: Array<String>) {
fun main(args: Array<String>) {
mcnugget(100)
mcnugget(100)
}</lang>
}</syntaxhighlight>


{{output}}
{{output}}
Line 1,138: Line 1,138:


=={{header|Locomotive Basic}}==
=={{header|Locomotive Basic}}==
<lang locobasic>100 CLEAR
<syntaxhighlight lang="locobasic">100 CLEAR
110 DIM a(100)
110 DIM a(100)
120 FOR a=0 TO 100/6
120 FOR a=0 TO 100/6
Line 1,152: Line 1,152:
220 NEXT n
220 NEXT n
230 PRINT"The Largest non McNugget number is:";l
230 PRINT"The Largest non McNugget number is:";l
240 END</lang>
240 END</syntaxhighlight>


{{output}}
{{output}}
Line 1,158: Line 1,158:


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>
<syntaxhighlight lang="lua">
function range(A,B)
function range(A,B)
return function()
return function()
Line 1,231: Line 1,231:


print(maximum(exclude(sum, range(1, N))))
print(maximum(exclude(sum, range(1, N))))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,238: Line 1,238:


=={{header|MAD}}==
=={{header|MAD}}==
<lang mad> NORMAL MODE IS INTEGER
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
BOOLEAN NUGGET
BOOLEAN NUGGET
DIMENSION NUGGET(101)
DIMENSION NUGGET(101)
Line 1,254: Line 1,254:
PRINT FORMAT F, I
PRINT FORMAT F, I
VECTOR VALUES F = $29HMAXIMUM NON-MCNUGGET NUMBER: ,I2*$
VECTOR VALUES F = $29HMAXIMUM NON-MCNUGGET NUMBER: ,I2*$
END OF PROGRAM </lang>
END OF PROGRAM </syntaxhighlight>
{{out}}
{{out}}
<pre>MAXIMUM NON-MCNUGGET NUMBER: 43</pre>
<pre>MAXIMUM NON-MCNUGGET NUMBER: 43</pre>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang mathematica>FrobeniusNumber[{6, 9, 20}]</lang>
<syntaxhighlight lang="mathematica">FrobeniusNumber[{6, 9, 20}]</syntaxhighlight>
{{out}}
{{out}}
<pre>43</pre>
<pre>43</pre>


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<lang modula2>MODULE McNuggets;
<syntaxhighlight lang="modula2">MODULE McNuggets;
FROM InOut IMPORT WriteCard, WriteString, WriteLn;
FROM InOut IMPORT WriteCard, WriteString, WriteLn;


Line 1,289: Line 1,289:
WriteCard(a, 2);
WriteCard(a, 2);
WriteLn();
WriteLn();
END McNuggets.</lang>
END McNuggets.</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number: 43</pre>
<pre>Maximum non-McNuggets number: 43</pre>


=={{header|MiniZinc}}==
=={{header|MiniZinc}}==
<syntaxhighlight lang="minizinc">
<lang MiniZinc>
%McNuggets. Nigel Galloway, August 27th., 2019
%McNuggets. Nigel Galloway, August 27th., 2019
var 0..99: n;
var 0..99: n;
Line 1,300: Line 1,300:
solve maximize n;
solve maximize n;
output [show(n)]
output [show(n)]
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,309: Line 1,309:


=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>const Limit = 100
<syntaxhighlight lang="nim">const Limit = 100


var mcnuggets: array[0..Limit, bool]
var mcnuggets: array[0..Limit, bool]
Line 1,321: Line 1,321:
if not mcnuggets[n]:
if not mcnuggets[n]:
echo "The largest non-McNuggets number is: ", n
echo "The largest non-McNuggets number is: ", n
break</lang>
break</syntaxhighlight>


{{out}}
{{out}}
Line 1,329: Line 1,329:
{{trans|Raku}}
{{trans|Raku}}
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use ntheory qw/forperm gcd vecmin/;
<syntaxhighlight lang="perl">use ntheory qw/forperm gcd vecmin/;


sub Mcnugget_number {
sub Mcnugget_number {
Line 1,371: Line 1,371:
for my $counts ([6,9,20], [6,7,20], [1,3,20], [10,5,18], [5,17,44], [2,4,6], [3,6,15]) {
for my $counts ([6,9,20], [6,7,20], [1,3,20], [10,5,18], [5,17,44], [2,4,6], [3,6,15]) {
print 'Maximum non-Mcnugget number using ' . join(', ', @$counts) . ' is: ' . Mcnugget_number($counts) . "\n"
print 'Maximum non-Mcnugget number using ' . join(', ', @$counts) . ' is: ' . Mcnugget_number($counts) . "\n"
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-Mcnugget number using 6, 9, 20 is: 43
<pre>Maximum non-Mcnugget number using 6, 9, 20 is: 43
Line 1,382: Line 1,382:


===Perl using Regex===
===Perl using Regex===
<lang Perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;


$_ = 1 . 0 x 100;
$_ = 1 . 0 x 100;
1 while s/ (?=1) (?:.{6}|.{9}|.{20}) \K 0 /1/x;
1 while s/ (?=1) (?:.{6}|.{9}|.{20}) \K 0 /1/x;
/01*$/ and print "Maximum non-Mcnugget number is: $-[0]\n";</lang>
/01*$/ and print "Maximum non-Mcnugget number is: $-[0]\n";</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-Mcnugget number is: 43</pre>
<pre>Maximum non-Mcnugget number is: 43</pre>
Line 1,393: Line 1,393:
=={{header|Phix}}==
=={{header|Phix}}==
{{trans|Go}}
{{trans|Go}}
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">limit</span><span style="color: #0000FF;">=</span><span style="color: #000000;">100</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">limit</span><span style="color: #0000FF;">=</span><span style="color: #000000;">100</span>
Line 1,405: Line 1,405:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Maximum non-McNuggets number is %d\n"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">rfind</span><span style="color: #0000FF;">(</span><span style="color: #004600;">false</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nuggets</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Maximum non-McNuggets number is %d\n"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">rfind</span><span style="color: #0000FF;">(</span><span style="color: #004600;">false</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nuggets</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,412: Line 1,412:
Also, since it is a bit more interesting, a
Also, since it is a bit more interesting, a
{{trans|Raku}}
{{trans|Raku}}
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">Mcnugget_number</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">counts</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">Mcnugget_number</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">counts</span><span style="color: #0000FF;">)</span>
Line 1,457: Line 1,457:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Maximum non-Mcnugget number using %V is: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">,</span><span style="color: #000000;">Mcnugget_number</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">)})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Maximum non-Mcnugget number using %V is: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">,</span><span style="color: #000000;">Mcnugget_number</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,471: Line 1,471:
=={{header|Picat}}==
=={{header|Picat}}==
Using constraint modelling (cp solver).
Using constraint modelling (cp solver).
<lang Picat>import cp.
<syntaxhighlight lang="picat">import cp.


go =>
go =>
Line 1,479: Line 1,479:
end,
end,
solve($[max(N)],N),
solve($[max(N)],N),
println(n=N).</lang>
println(n=N).</syntaxhighlight>


{{out}}
{{out}}
Line 1,485: Line 1,485:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(de nuggets1 (M)
<syntaxhighlight lang="picolisp">(de nuggets1 (M)
(let Lst (range 0 M)
(let Lst (range 0 M)
(for A (range 0 M 6)
(for A (range 0 M 6)
Line 1,491: Line 1,491:
(for C (range B M 20)
(for C (range B M 20)
(set (nth Lst (inc C))) ) ) )
(set (nth Lst (inc C))) ) ) )
(apply max Lst) ) )</lang>
(apply max Lst) ) )</syntaxhighlight>
Generator from fiber:
Generator from fiber:
<lang PicoLisp>(de nugg (M)
<syntaxhighlight lang="picolisp">(de nugg (M)
(co 'nugget
(co 'nugget
(for A (range 0 M 6)
(for A (range 0 M 6)
Line 1,503: Line 1,503:
(while (nugg 100)
(while (nugg 100)
(set (nth Lst @)) )
(set (nth Lst @)) )
(apply max Lst) ) )</lang>
(apply max Lst) ) )</syntaxhighlight>
Test versions against each other:
Test versions against each other:
<lang PicoLis>(test
<syntaxhighlight lang="picolis">(test
T
T
(=
(=
43
43
(nuggets1 100)
(nuggets1 100)
(nuggets2 100) ) )</lang>
(nuggets2 100) ) )</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli>mcnugget: procedure options(main);
<syntaxhighlight lang="pli">mcnugget: procedure options(main);
declare nugget(0:100) bit, (a, b, c) fixed;
declare nugget(0:100) bit, (a, b, c) fixed;
do a=0 to 100; nugget(a) = '0'b; end;
do a=0 to 100; nugget(a) = '0'b; end;
Line 1,531: Line 1,531:
end;
end;
end;
end;
end mcnugget;</lang>
end mcnugget;</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number: 43</pre>
<pre>Maximum non-McNuggets number: 43</pre>


=={{header|PL/M}}==
=={{header|PL/M}}==
<lang plm>100H:
<syntaxhighlight lang="plm">100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
Line 1,569: Line 1,569:
CALL PRINT$NUMBER(A);
CALL PRINT$NUMBER(A);
CALL EXIT;
CALL EXIT;
EOF</lang>
EOF</syntaxhighlight>
{{out}}
{{out}}
<pre>43</pre>
<pre>43</pre>
Line 1,575: Line 1,575:
=={{header|PowerShell}}==
=={{header|PowerShell}}==
{{trans|UNIX Shell}}
{{trans|UNIX Shell}}
<lang powershell>$possible = @{}
<syntaxhighlight lang="powershell">$possible = @{}
For ($i=0; $i -lt 18; $i++) {
For ($i=0; $i -lt 18; $i++) {
For ($j=0; $j -lt 13; $j++) {
For ($j=0; $j -lt 13; $j++) {
Line 1,592: Line 1,592:
}
}
}
}
Write-Host "Maximum non-McNuggets number is $n"</lang>
Write-Host "Maximum non-McNuggets number is $n"</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number is 43</pre>
<pre>Maximum non-McNuggets number is 43</pre>
Line 1,599: Line 1,599:
===Python: REPL===
===Python: REPL===
It's a simple solution done on the command line:
It's a simple solution done on the command line:
<lang python>>>> from itertools import product
<syntaxhighlight lang="python">>>> from itertools import product
>>> nuggets = set(range(101))
>>> nuggets = set(range(101))
>>> for s, n, t in product(range(100//6+1), range(100//9+1), range(100//20+1)):
>>> for s, n, t in product(range(100//6+1), range(100//9+1), range(100//20+1)):
Line 1,607: Line 1,607:
>>> max(nuggets)
>>> max(nuggets)
43
43
>>> </lang>
>>> </syntaxhighlight>


Single expression version (expect to be slower, however no noticeable difference on a Celeron B820 and haven't benchmarked):
Single expression version (expect to be slower, however no noticeable difference on a Celeron B820 and haven't benchmarked):
<lang python>>>> from itertools import product
<syntaxhighlight lang="python">>>> from itertools import product
>>> max(x for x in range(100+1) if x not in
>>> max(x for x in range(100+1) if x not in
... (6*s + 9*n + 20*t for s, n, t in
... (6*s + 9*n + 20*t for s, n, t in
... product(range(100//6+1), range(100//9+1), range(100//20+1))))
... product(range(100//6+1), range(100//9+1), range(100//20+1))))
43
43
>>> </lang>
>>> </syntaxhighlight>


===Using Set Comprehension===
===Using Set Comprehension===
{{trans|FSharp}}
{{trans|FSharp}}
<lang python>
<syntaxhighlight lang="python">
#Wherein I observe that Set Comprehension is not intrinsically dysfunctional. Nigel Galloway: October 28th., 2018
#Wherein I observe that Set Comprehension is not intrinsically dysfunctional. Nigel Galloway: October 28th., 2018
n = {n for x in range(0,101,20) for y in range(x,101,9) for n in range(y,101,6)}
n = {n for x in range(0,101,20) for y in range(x,101,9) for n in range(y,101,6)}
g = {n for n in range(101)}
g = {n for n in range(101)}
print(max(g.difference(n)))
print(max(g.difference(n)))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,636: Line 1,636:


{{Works with|Python|3.7}}
{{Works with|Python|3.7}}
<lang python>'''mcNuggets list monad'''
<syntaxhighlight lang="python">'''mcNuggets list monad'''


from itertools import (chain, dropwhile)
from itertools import (chain, dropwhile)
Line 1,762: Line 1,762:
# MAIN ---
# MAIN ---
if __name__ == '__main__':
if __name__ == '__main__':
main()</lang>
main()</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 1,771: Line 1,771:


=={{header|Quackery}}==
=={{header|Quackery}}==
<lang Quackery>0 temp put
<syntaxhighlight lang="quackery">0 temp put
100 6 / times
100 6 / times
[ i 6 *
[ i 6 *
Line 1,796: Line 1,796:
[ say "The largest non-McNugget number below 101 is "
[ say "The largest non-McNugget number below 101 is "
echo ]
echo ]
char . emit</lang>
char . emit</syntaxhighlight>


'''Output:'''
'''Output:'''
Line 1,805: Line 1,805:


There are two natural approaches. The first is to generate all valid x, y, and z and then apply the function:
There are two natural approaches. The first is to generate all valid x, y, and z and then apply the function:
<lang rsplus>allInputs <- expand.grid(x = 0:(100 %/% 6), y = 0:(100 %/% 9), z = 0:(100 %/% 20))
<syntaxhighlight lang="rsplus">allInputs <- expand.grid(x = 0:(100 %/% 6), y = 0:(100 %/% 9), z = 0:(100 %/% 20))
mcNuggets <- do.call(function(x, y, z) 6 * x + 9 * y + 20 * z, allInputs)</lang>
mcNuggets <- do.call(function(x, y, z) 6 * x + 9 * y + 20 * z, allInputs)</syntaxhighlight>
The second is to find all of the valid 6x, 9y, and 20z, and then sum them:
The second is to find all of the valid 6x, 9y, and 20z, and then sum them:
<lang rsplus>mcNuggets2 <- rowSums(expand.grid(seq(0, 100, 6), seq(0, 100, 9), seq(0, 100, 20)))</lang>
<syntaxhighlight lang="rsplus">mcNuggets2 <- rowSums(expand.grid(seq(0, 100, 6), seq(0, 100, 9), seq(0, 100, 20)))</syntaxhighlight>
Either way, we get identical results, as checked by:
Either way, we get identical results, as checked by:
<lang rsplus>all(mcNuggets == mcNuggets2)</lang>
<syntaxhighlight lang="rsplus">all(mcNuggets == mcNuggets2)</syntaxhighlight>
For our final answer, note that our choice to remove values from the vector 0:100 means our outputs will already be sorted, unique, and no greater than 100.
For our final answer, note that our choice to remove values from the vector 0:100 means our outputs will already be sorted, unique, and no greater than 100.
<lang rsplus>results <- setdiff(0:100, mcNuggets)
<syntaxhighlight lang="rsplus">results <- setdiff(0:100, mcNuggets)
cat("The non-McNuggets numbers that are no greater than 100 are:", results, "\nThe largest is", max(results), "\n")</lang>
cat("The non-McNuggets numbers that are no greater than 100 are:", results, "\nThe largest is", max(results), "\n")</syntaxhighlight>
Ultimately, this can be done in one line:
Ultimately, this can be done in one line:
<lang rsplus>max(setdiff(0:100, rowSums(expand.grid(seq(0, 100, 6), seq(0, 100, 9), seq(0, 100, 20)))))</lang>
<syntaxhighlight lang="rsplus">max(setdiff(0:100, rowSums(expand.grid(seq(0, 100, 6), seq(0, 100, 9), seq(0, 100, 20)))))</syntaxhighlight>
However, using seq without naming its arguments is considered bad practice. It works here, but breaking this code up is probably a better idea.
However, using seq without naming its arguments is considered bad practice. It works here, but breaking this code up is probably a better idea.
{{output}}
{{output}}
Line 1,829: Line 1,829:
{{trans|Python}} (one of them)
{{trans|Python}} (one of them)


<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket
(apply max (set->list (for*/fold ((s (list->set (range 1 101))))
(apply max (set->list (for*/fold ((s (list->set (range 1 101))))
((x (in-range 0 101 20))
((x (in-range 0 101 20))
(y (in-range x 101 9))
(y (in-range x 101 9))
(n (in-range y 101 6)))
(n (in-range y 101 6)))
(set-remove s n))))</lang>
(set-remove s n))))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
Line 1,843: Line 1,843:
Finds the smallest count value, then looks for the first run of consecutive count totals able to be generated, that is at least the length of the smallest count size. From then on, every number can be generated by simply adding multiples of the minimum count to each of the totals in that run.
Finds the smallest count value, then looks for the first run of consecutive count totals able to be generated, that is at least the length of the smallest count size. From then on, every number can be generated by simply adding multiples of the minimum count to each of the totals in that run.


<lang perl6>sub Mcnugget-number (*@counts) {
<syntaxhighlight lang="raku" line>sub Mcnugget-number (*@counts) {


return '∞' if 1 < [gcd] @counts;
return '∞' if 1 < [gcd] @counts;
Line 1,873: Line 1,873:
put "Maximum non-Mcnugget number using {$counts.join: ', '} is: ",
put "Maximum non-Mcnugget number using {$counts.join: ', '} is: ",
Mcnugget-number(|$counts)
Mcnugget-number(|$counts)
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-Mcnugget number using 6, 9, 20 is: 43
<pre>Maximum non-Mcnugget number using 6, 9, 20 is: 43
Line 1,890: Line 1,890:
:* &nbsp; excludes meals that have a multiple order of nuggets
:* &nbsp; excludes meals that have a multiple order of nuggets
:* &nbsp; automatically computes the '''high''' value algebraically instead of using &nbsp; '''100'''.
:* &nbsp; automatically computes the '''high''' value algebraically instead of using &nbsp; '''100'''.
<lang rexx>/*REXX pgm solves the McNuggets problem: the largest McNugget number for given meals. */
<syntaxhighlight lang="rexx">/*REXX pgm solves the McNuggets problem: the largest McNugget number for given meals. */
parse arg y /*obtain optional arguments from the CL*/
parse arg y /*obtain optional arguments from the CL*/
if y='' | y="," then y= 6 9 20 /*Not specified? Then use the defaults*/
if y='' | y="," then y= 6 9 20 /*Not specified? Then use the defaults*/
Line 1,934: Line 1,934:
do while $\==''; parse var $ y $; y= abs(y); if y==0 then iterate
do while $\==''; parse var $ y $; y= abs(y); if y==0 then iterate
do until y==0; parse value x//y y with y x; end
do until y==0; parse value x//y y with y x; end
end; return x</lang>
end; return x</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
Line 1,943: Line 1,943:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
Nuggets = list(100)
Nuggets = list(100)


Line 1,963: Line 1,963:
ok
ok
next
next
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,971: Line 1,971:
=={{header|Ruby}}==
=={{header|Ruby}}==
{{trans|Go}}
{{trans|Go}}
<lang ruby>def mcnugget(limit)
<syntaxhighlight lang="ruby">def mcnugget(limit)
sv = (0..limit).to_a
sv = (0..limit).to_a


Line 1,985: Line 1,985:
end
end


puts(mcnugget 100)</lang>
puts(mcnugget 100)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,991: Line 1,991:
</pre>
</pre>
Generic solution, allowing for more or less then 3 portion-sizes:
Generic solution, allowing for more or less then 3 portion-sizes:
<lang ruby>limit = 100
<syntaxhighlight lang="ruby">limit = 100
nugget_portions = [6, 9, 20]
nugget_portions = [6, 9, 20]


arrs = nugget_portions.map{|n| 0.step(limit, n).to_a }
arrs = nugget_portions.map{|n| 0.step(limit, n).to_a }
hits = arrs.pop.product(*arrs).map(&:sum)
hits = arrs.pop.product(*arrs).map(&:sum)
p ((0..limit).to_a - hits).max # => 43</lang>
p ((0..limit).to_a - hits).max # => 43</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
Line 2,002: Line 2,002:
Generalization of Rødseth’s Algorithm explained in [https://parramining.blogspot.com/2019/09/generalization-of-rdseths-algorithm-for.html post].
Generalization of Rødseth’s Algorithm explained in [https://parramining.blogspot.com/2019/09/generalization-of-rdseths-algorithm-for.html post].
Working code: [https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1424a910a196fb3d0e964c754fbf325c Rust playground].
Working code: [https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1424a910a196fb3d0e964c754fbf325c Rust playground].
<lang rust>fn main() {
<syntaxhighlight lang="rust">fn main() {
let test_cases = vec![
let test_cases = vec![
[6, 9, 20],
[6, 9, 20],
Line 2,090: Line 2,090:
(m * y + cc) / aa
(m * y + cc) / aa
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,108: Line 2,108:
=={{header|Swift}}==
=={{header|Swift}}==


<lang swift>func maxNugget(limit: Int) -> Int {
<syntaxhighlight lang="swift">func maxNugget(limit: Int) -> Int {
var (max, sixes, nines, twenties, i) = (0, 0, 0, 0, 0)
var (max, sixes, nines, twenties, i) = (0, 0, 0, 0, 0)


Line 2,152: Line 2,152:
}
}


print(maxNugget(limit: 100))</lang>
print(maxNugget(limit: 100))</syntaxhighlight>


{{out}}
{{out}}
Line 2,159: Line 2,159:


=={{header|Tailspin}}==
=={{header|Tailspin}}==
<lang tailspin>
<syntaxhighlight lang="tailspin">
templates largestNonMcNuggetNumber
templates largestNonMcNuggetNumber
@: { largest: 0, mcNuggetNumbers: [1..$+20 -> 0] };
@: { largest: 0, mcNuggetNumbers: [1..$+20 -> 0] };
Line 2,170: Line 2,170:


100 -> largestNonMcNuggetNumber -> !OUT::write
100 -> largestNonMcNuggetNumber -> !OUT::write
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,181: Line 2,181:
{{works with|ksh}}
{{works with|ksh}}
{{works with|zsh}}
{{works with|zsh}}
<lang bash>possible=()
<syntaxhighlight lang="bash">possible=()
for (( i=0; i<18; ++i )); do
for (( i=0; i<18; ++i )); do
for (( j=0; j<13; ++j )); do
for (( j=0; j<13; ++j )); do
Line 2,200: Line 2,200:
done
done


printf 'Maximum non-McNuggets number is %d\n' $n</lang>
printf 'Maximum non-McNuggets number is %d\n' $n</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number is 43</pre>
<pre>Maximum non-McNuggets number is 43</pre>
{{works with|sh}}
{{works with|sh}}
<lang bash>possible=
<syntaxhighlight lang="bash">possible=
i=0
i=0
while [ $i -lt 18 ]; do
while [ $i -lt 18 ]; do
Line 2,227: Line 2,227:
break
break
done
done
echo "Maximum non-McNuggets number is $n"</lang>
echo "Maximum non-McNuggets number is $n"</syntaxhighlight>
{{out}}
{{out}}
<pre>Maximum non-McNuggets number is 43</pre>
<pre>Maximum non-McNuggets number is 43</pre>
Line 2,233: Line 2,233:
=={{header|Vlang}}==
=={{header|Vlang}}==
{{trans|Go}}
{{trans|Go}}
<lang vlang>fn mcnugget(limit int) {
<syntaxhighlight lang="vlang">fn mcnugget(limit int) {
mut sv := []bool{len: limit+1} // all false by default
mut sv := []bool{len: limit+1} // all false by default
for s := 0; s <= limit; s += 6 {
for s := 0; s <= limit; s += 6 {
Line 2,252: Line 2,252:
fn main() {
fn main() {
mcnugget(100)
mcnugget(100)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,259: Line 2,259:


=={{header|VTL-2}}==
=={{header|VTL-2}}==
<lang VTL2>10 N=0
<syntaxhighlight lang="vtl2">10 N=0
20 :N+1)=0
20 :N+1)=0
30 N=N+1
30 N=N+1
Line 2,277: Line 2,277:
170 #=:N+1)
170 #=:N+1)
180 ?="Largest non-McNuggets number: ";
180 ?="Largest non-McNuggets number: ";
190 ?=N</lang>
190 ?=N</syntaxhighlight>
{{out}}
{{out}}
<pre>Largest non-McNuggets number: 43</pre>
<pre>Largest non-McNuggets number: 43</pre>
Line 2,283: Line 2,283:
=={{header|Wren}}==
=={{header|Wren}}==
{{trans|Go}}
{{trans|Go}}
<lang ecmascript>var mcnugget = Fn.new { |limit|
<syntaxhighlight lang="ecmascript">var mcnugget = Fn.new { |limit|
var sv = List.filled(limit+1, false)
var sv = List.filled(limit+1, false)
var s = 0
var s = 0
Line 2,306: Line 2,306:
}
}


mcnugget.call(100)</lang>
mcnugget.call(100)</syntaxhighlight>


{{out}}
{{out}}
Line 2,314: Line 2,314:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>int N, A(101), X, Y, Z;
<syntaxhighlight lang="xpl0">int N, A(101), X, Y, Z;
[for N:= 0 to 100 do A(N):= false;
[for N:= 0 to 100 do A(N):= false;
for X:= 0 to 100/6 do
for X:= 0 to 100/6 do
Line 2,327: Line 2,327:
exit;
exit;
];
];
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 2,334: Line 2,334:
=={{header|zkl}}==
=={{header|zkl}}==
{{trans|Python}}
{{trans|Python}}
<lang zkl>nuggets:=[0..101].pump(List()); // (0,1,2,3..101), mutable
<syntaxhighlight lang="zkl">nuggets:=[0..101].pump(List()); // (0,1,2,3..101), mutable
foreach s,n,t in ([0..100/6],[0..100/9],[0..100/20])
foreach s,n,t in ([0..100/6],[0..100/9],[0..100/20])
{ nuggets[(6*s + 9*n + 20*t).min(101)]=0 }
{ nuggets[(6*s + 9*n + 20*t).min(101)]=0 }
println((0).max(nuggets));</lang>
println((0).max(nuggets));</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>