Skip to content

Instantly share code, notes, and snippets.

@theoknock
Last active November 11, 2023 04:09
Show Gist options
  • Save theoknock/a38a3ebaf06094177da284ea9f8f3ebc to your computer and use it in GitHub Desktop.
Save theoknock/a38a3ebaf06094177da284ea9f8f3ebc to your computer and use it in GitHub Desktop.
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
}
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