Advertisement
31ph4n70m

Neumann's_Random_Generator.lua

Dec 19th, 2019
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. -- lua solution to codeabbey challenge 24
  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. function isInArray(array, elem)
  19.     for l, j in pairs(array) do
  20.         if elem == j then
  21.             return true
  22.         end
  23.     end
  24. end
  25.  
  26. INP1 = tonumber(io.read())
  27. INP2 = map(tonumber, split(io.read(), " "))
  28. counter = 1
  29. rsp = {}
  30. vals = {}
  31. for k, i in pairs(INP2) do
  32.     aux = i
  33.     while true do
  34.         aux2 = math.modf((aux*aux / 100) % 10000)
  35.         if isInArray(vals, aux2) then
  36.             table.insert(rsp, counter)
  37.             break
  38.         end
  39.         table.insert(vals, aux)
  40.         counter = counter + 1
  41.         aux = aux2
  42.     end
  43.     counter = 1
  44.     vals = {}
  45. end
  46. print(table.concat(rsp, " "))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement