Created
October 18, 2019 16:03
-
-
Save nuclearace/5988ee84358dae017693fae0b36cde28 to your computer and use it in GitHub Desktop.
mcnugget numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment