47 lines
827 B
Lua
47 lines
827 B
Lua
io.input("test")
|
|
io.input("input")
|
|
|
|
function s2d( s )
|
|
local b = #s - 1
|
|
local num = 0
|
|
for i = 1, #s do
|
|
local sub = string.sub( s, i, i )
|
|
local d = tonumber(sub)
|
|
if not d then
|
|
if sub=="-" then d=-1
|
|
elseif sub=="=" then d=-2 end
|
|
end
|
|
num = num + d*(5^b)
|
|
b = b - 1
|
|
end
|
|
return num
|
|
end
|
|
|
|
function d2s( num )
|
|
local s = ""
|
|
repeat
|
|
local mod = num % 5
|
|
local rest = num // 5
|
|
local dif = mod - 5
|
|
local digit
|
|
if dif >= -2 then
|
|
rest = rest + 1
|
|
if dif == -2 then digit = "="
|
|
elseif dif == -1 then digit = "-" end
|
|
else
|
|
digit = string.format("%d", mod)
|
|
end
|
|
s = digit .. s
|
|
num = rest
|
|
until num == 0
|
|
return s
|
|
end
|
|
|
|
local sum = 0
|
|
for line in io.lines() do
|
|
sum = sum + s2d(line)
|
|
end
|
|
|
|
local result1 = d2s(sum)
|
|
print("part1:", result1)
|