Jump to content

McNuggets problem: Difference between revisions

Add Swift
(Add Swift)
Line 1,407:
g(6, 15, 1) = -1
</pre>
 
=={{header|Swift}}==
 
<lang swift>func maxNugget(limit: Int) -> Int {
var (max, sixes, nines, twenties, i) = (0, 0, 0, 0, 0)
 
mainLoop: while i < limit {
sixes = 0
 
while sixes * 6 < i {
if sixes * 6 == i {
i += 1
continue mainLoop
}
 
nines = 0
 
while nines * 9 < i {
if sixes * 6 + nines * 9 == i {
i += 1
continue mainLoop
}
 
twenties = 0
 
while twenties * 20 < i {
if sixes * 6 + nines * 9 + twenties * 20 == i {
i += 1
continue mainLoop
}
 
twenties += 1
}
 
nines += 1
}
 
sixes += 1
}
 
max = i
i += 1
}
 
return max
}
 
print(maxNugget(limit: 100))</lang>
 
{{out}}
 
<pre>43</pre>
 
=={{header|Tailspin}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.