Advertisement
wwwRong

permutation_case_lua

Oct 28th, 2021
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.53 KB | None | 0 0
  1. local concat, insert, unpack = table.concat, table.insert, table.unpack
  2. function permutecase(word)
  3.   local ret = {}
  4.   for i = #word, 1, -1 do
  5.     if i == #word then
  6.       ret[#ret+1] = word:sub(i,i):lower()
  7.       ret[#ret+1] = word:sub(i,i):upper()
  8.     else
  9.       for j = 1, #ret do
  10.         local case = ret[j]
  11.         ret[#ret+1] = word:sub(i,i):upper() .. ret[j]
  12.         ret[j] = word:sub(i,i):lower() .. ret[j]
  13.       end
  14.     end
  15.   end
  16.   return ret
  17. end
  18.  
  19. for i, v in ipairs(permutecase("pass")) do
  20.   print(i, v)
  21. end
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement