Last active
November 11, 2023 04:09
-
-
Save theoknock/a38a3ebaf06094177da284ea9f8f3ebc to your computer and use it in GitHub Desktop.
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 makeIncrementerWithReset(maximumValue: Int) -> ((Int) -> [Int]) { | |
var counter = 0 | |
let counter_max = maximumValue | |
func incrementCounter(count: Int) -> [Int] { | |
var numbersArray = [Int](repeating: 0, count: count) | |
for index in (0 ..< count) { | |
let value = ((counter_max ^ 0) ^ (counter ^ counter_max)) | |
numbersArray[index] = value | |
counter = (-(~(value))) | |
counter = counter % counter_max | |
if counter == counter_max { | |
counter = 0 | |
} | |
print("\(index)\t\(value)") | |
} | |
return numbersArray | |
} | |
return incrementCounter | |
} |
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
let incrementer = makeIncrementerWithReset(maximumValue: 32) | |
incrementer(40) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment