Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sum = 0
- for line in io.lines(arg[1]) do
- local n = 0
- local pos = 0
- for i = #line, 1, -1 do
- local digit = line:sub(i,i)
- if digit == "-" then
- n = n + -1 * (5^pos)
- elseif digit == "=" then
- n = n + -2 * (5^pos)
- else
- n = n + tonumber(digit) * (5^pos)
- end
- pos = pos + 1
- end
- sum = sum + n
- end
- sum = math.floor(sum)
- local function convert(n)
- local rems = {}
- while n > 0 do
- table.insert(rems, n % 5)
- n = math.floor(n / 5)
- end
- return rems
- end
- local rems = convert(sum)
- local ans = ""
- for i, n in ipairs(rems) do
- if n == 0 or n == 1 or n == 2 then
- ans = n .. ans
- elseif n == 3 then
- ans = "=" .. ans
- rems[i+1] = rems[i+1] + 1
- elseif n == 4 then
- ans = "-" .. ans
- rems[i+1] = rems[i+1] + 1
- end
- end
- print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement