Skip to content

Instantly share code, notes, and snippets.

@eelstork
Created August 8, 2016 04:01
Show Gist options
  • Save eelstork/6dfeb05a41976adfd184549f1f4e37ac to your computer and use it in GitHub Desktop.
Save eelstork/6dfeb05a41976adfd184549f1f4e37ac to your computer and use it in GitHub Desktop.
Count in base N
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