lua - Find all upper/lower/mixed combinations of a string -
i need game server using lua..
i able save combinations of name string can used with:
if exists (string)
example:
abc_-123 abc_-123 abc_-123 abc_-123 abc_-123
etc
in game numbers, letters , _ -
. can used names.
(a_b-c, a-b.c, ab_8 ... etc)
i understand logic don't know how code it:d
0-lower 1-upper
then
000 001
etc
you can use recursive generator. first parameter contains left part of string generated far, , second parameter remaining right part of original string.
function combinations(s1, s2) if s2:len() > 0 local c = s2:sub(1, 1) local l = c:lower() local u = c:upper() if l == u combinations(s1 .. c, s2:sub(2)) else combinations(s1 .. l, s2:sub(2)) combinations(s1 .. u, s2:sub(2)) end else print(s1) end end
so function called in way.
combinations("", "abc_-123")
you have store intermediate results instead of printing them.
Comments
Post a Comment