# Algorithm for testing every combination of letters/numbers/characters

Hello,
This is a basic algorithm for testing any combination of letter/numbers/characters you want:

``````function setup()
parameter.integer("GuessAmnt",1,20,5)
parameter.integer("MinASCIIChar",0,255,33)
parameter.integer("MaxASCIIChar",0,255,126)
parameter.integer("TestsPerFrame",1,20,1)
parameter.action("Start Guessing",function() guessing = true end)

currentWord = {}
guessing = false
wordCount = 0

--[[for i = 1,255 do
print(i,string.char(i))
end]]
end

function draw()
background(0, 0, 0, 255)
if guessing then
for i = 1,TestsPerFrame do
local word = nextWord(GuessAmnt)
if string.len(word) == 0 then
guessing = false
wordCount = 0
currentWord = {}
else
wordCount = wordCount + 1
pushStyle()
pushMatrix()
--fontSize(100)
fill(255)
translate(WIDTH/2,HEIGHT/2)
scale(10) -- Scaled to reduce frame times
text(word.."\
"..wordCount,0,0)
popStyle()
popMatrix()
end
end
end
end

function nextWord(len)
if #currentWord == 0 or #currentWord < len then
table.insert(currentWord,MinASCIIChar)
else
local looping = true
while looping == true do
local c = table.remove(currentWord)
if c < MaxASCIIChar then
c = c + 1
table.insert(currentWord,c)
looping = false
elseif #currentWord == 0 then
looping = false
end
end
end
return asciiToStr(currentWord)
end

function asciiToStr(tbl)
local str = ""
for i,v in ipairs(tbl) do
str = str..string.char(v)
end
return str
end
``````

However, this is probably utterly and completely useless because of this:
Let’s assume we’re testing 93 characters (the only readable ones) on a 5 letter word. Let’s also assume this program is running 60 FPS and tests 5 rounds a frame. That means that 93^5/60/5 gives us the number of seconds it takes to test all the items. That turns out to about 23189612 seconds. To put that into better perspective, that’s about 3/4 of a year. (Please LMK if there was a mistake in my math.)
That being said, I thought I might share this fun piece of code.
Thanks!