2022-12-20 20:51:38 +00:00
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
|
|
|
|
import sys
|
2022-12-25 10:34:49 +00:00
|
|
|
|
|
|
|
lines = sys.stdin.read().splitlines()
|
|
|
|
|
|
|
|
coeffs = {"2": 2, "1": 1, "0": 0, "-": -1, "=": -2}
|
|
|
|
|
|
|
|
|
|
|
|
def snafu2number(number: str) -> int:
|
|
|
|
value = 0
|
|
|
|
for c in number:
|
|
|
|
value *= 5
|
|
|
|
value += coeffs[c]
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
def number2snafu(number: int) -> str:
|
|
|
|
values = ["0", "1", "2", "=", "-"]
|
|
|
|
res = ""
|
|
|
|
while number > 0:
|
|
|
|
mod = number % 5
|
|
|
|
res = res + values[mod]
|
|
|
|
number = number // 5 + int(mod >= 3)
|
|
|
|
return "".join(reversed(res))
|
|
|
|
|
|
|
|
|
|
|
|
answer_1 = number2snafu(sum(map(snafu2number, lines)))
|
|
|
|
print(f"answer 1 is {answer_1}")
|