2023-02-09 21:58:25 +00:00
|
|
|
let strtable = []
|
|
|
|
let strLen = 4 // length of all strings to generate
|
|
|
|
let AByte = "A":byte() // grabs the ascii value of 'A'
|
2021-02-23 17:50:41 +00:00
|
|
|
|
|
|
|
proto stringBuilder
|
2023-02-09 21:58:25 +00:00
|
|
|
func __init(self, length)
|
2021-02-23 17:50:41 +00:00
|
|
|
self.len = length
|
|
|
|
end
|
|
|
|
|
|
|
|
// we are the iterator object lol
|
2023-02-09 21:58:25 +00:00
|
|
|
func __iter(self)
|
2021-02-23 17:50:41 +00:00
|
|
|
self.x = 0
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
2023-02-09 21:58:25 +00:00
|
|
|
func __next(self)
|
|
|
|
let x = self.x++
|
2021-02-23 17:50:41 +00:00
|
|
|
|
|
|
|
// 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
|
2023-02-09 21:58:25 +00:00
|
|
|
let str = ""
|
|
|
|
for (let i = 0; i < self.len; i++) do
|
2021-02-23 17:50:41 +00:00
|
|
|
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
|