Created
August 8, 2016 04:01
-
-
Save eelstork/6dfeb05a41976adfd184549f1f4e37ac to your computer and use it in GitHub Desktop.
Count in base N
This file contains 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
var base = 3 | |
var max = 20 | |
var data = [0] | |
var index = 0 | |
for _ in 1...max{ | |
var applied = false | |
while !applied{ | |
if index>=data.count{ | |
data.append(0) | |
} | |
if data[index]<base-1 { | |
data[index] += 1 | |
while(index>0){ | |
index-=1 | |
data[index]=0 | |
} | |
applied=true | |
}else{ | |
index+=1 | |
} | |
} | |
var offset = data.count | |
var value:String = "" | |
while(offset>0){ | |
offset-=1 | |
value.appendContentsOf("\(data[offset])") | |
} | |
print("Value \(value)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment