mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-27 17:30:06 +00:00
CPunch
8ac8085d20
- 'var' has some weird scoping connotations with users of JS. better to change it to 'let', which will decide whether to make the variable a local or a global - 'func' looks visually appealing lol - some minor refactoring done in cparse.c
40 lines
926 B
Plaintext
40 lines
926 B
Plaintext
let strtable = []
|
|
let strLen = 4 // length of all strings to generate
|
|
let AByte = "A":byte() // grabs the ascii value of 'A'
|
|
|
|
proto stringBuilder
|
|
func __init(self, length)
|
|
self.len = length
|
|
end
|
|
|
|
// we are the iterator object lol
|
|
func __iter(self)
|
|
self.x = 0
|
|
return self
|
|
end
|
|
|
|
func __next(self)
|
|
let x = self.x++
|
|
|
|
// if we've generated all the possible strings, return nil ending the loop
|
|
if x >= 26 ^ self.len then
|
|
return nil
|
|
end
|
|
|
|
// generate the string
|
|
let str = ""
|
|
for (let i = 0; i < self.len; i++) do
|
|
str = string.char(AByte + (x % 26)) .. str
|
|
|
|
x = math.floor(x / 26)
|
|
end
|
|
|
|
return str
|
|
end
|
|
end
|
|
|
|
// generate a bunch of strings & populate the table
|
|
print("generating " .. 26 ^ strLen .. " strings...")
|
|
for str in stringBuilder(strLen) do
|
|
strtable[str] = true
|
|
end |