Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
45
Task/McNuggets-problem/Swift/mcnuggets-problem.swift
Normal file
45
Task/McNuggets-problem/Swift/mcnuggets-problem.swift
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue