Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- lua solution to codeabbey challenge 24
- function split(s, delimiter)
- result = {};
- for match in (s..delimiter):gmatch("(.-)"..delimiter) do
- table.insert(result, match);
- end
- return result;
- end
- function map(func, array)
- local new_array = {}
- for i,v in ipairs(array) do
- new_array[i] = func(v)
- end
- return new_array
- end
- function isInArray(array, elem)
- for l, j in pairs(array) do
- if elem == j then
- return true
- end
- end
- end
- INP1 = tonumber(io.read())
- INP2 = map(tonumber, split(io.read(), " "))
- counter = 1
- rsp = {}
- vals = {}
- for k, i in pairs(INP2) do
- aux = i
- while true do
- aux2 = math.modf((aux*aux / 100) % 10000)
- if isInArray(vals, aux2) then
- table.insert(rsp, counter)
- break
- end
- table.insert(vals, aux)
- counter = counter + 1
- aux = aux2
- end
- counter = 1
- vals = {}
- end
- print(table.concat(rsp, " "))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement