31ph4n70m

Funny_Words_Generator.lua

Dec 17th, 2019
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. -- lua solution to codabbey challenge 72
  2. function split(s, delimiter)
  3.     result = {};
  4.     for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  5.       table.insert(result, match);
  6.     end
  7.     return result;
  8. end
  9.  
  10. function map(func, array)
  11.     local new_array = {}
  12.     for i,v in ipairs(array) do
  13.         new_array[i] = func(v)
  14.     end
  15.     return new_array
  16. end
  17.  
  18. INP1 = map(tonumber, split(io.read(), " "))
  19. INP2 = map(tonumber, split(io.read(), " "))
  20. CON = {}
  21. con = "bcdfghjklmnprstvwxz"
  22. con:gsub(".",function(c) table.insert(CON,c) end)
  23. VOW = {}
  24. vow = "aeiou"
  25. vow:gsub(".",function(c) table.insert(VOW,c) end)
  26. A = 445
  27. C = 700001
  28. M = 2097152
  29. XN = INP1[2]
  30. LI = 0
  31. RSP = {}
  32. for k, wl in pairs(INP2) do
  33.     WORD = {}
  34.     for i=1,wl do
  35.         XN = (A*XN + C) % M
  36.         if i % 2 == 0 then
  37.             LI = XN % 5
  38.             table.insert(WORD, VOW[LI+1])
  39.         else
  40.             LI = XN % 19
  41.             table.insert(WORD, CON[LI+1])
  42.         end
  43.     end
  44.     aux = table.concat(WORD, "")
  45.     table.insert(RSP, aux)
  46. end
  47. print(table.concat(RSP, " "))
Add Comment
Please, Sign In to add comment