This commit is contained in:
Mikaël Capelle 2022-12-25 11:34:49 +01:00
parent 0508d95e33
commit dd80b30e26
3 changed files with 163 additions and 0 deletions

View File

@ -1,3 +1,29 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
import sys import sys
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}")

View File

@ -0,0 +1,124 @@
21-0==1=-0
102211-220011-----
1=2=111=10=-
12-2=022=2
1=--=11
12-2211000=0011-0-
1=1-
2=0-10-=21-2
1210-
2=1-=
1=0=12=2112--11=
2--211=200
20-02-20
12=12=0=0=1
22===21=-0102-012=
1--=-121
1=02=2-=
12-0-20
2=---=0102--00=22
1=2==0=2=
11-1112
2--012
12=12=--212-0-==-02
1=220
20===1
2210-02=12-022-=1-
22--1-==1
211-1=1=0-==1
10
1-1-02
1=-2==-0=21
1=102
20121021
1=2=22=001200-==1020
10211-1-20--10-1=
1222==1--=1--11-=
11211211
1=101-20=
1=1-11=0=000
1=-=101
2
1000-2
1==0=210=1=21222-=2
1=1==2-
2--020=2=2===-
2-
2=0
222101=22=-21=11
2=
121201-0-20-2-=11=
10=
1212=20=2=-=-1--1
2-20-=212=01
1=1--00--0=12=-00
22--
22
22===1=-0-22-
111-=
2-111=0021=2
200=22-=12-2=
1==-=1=0
1--=02-0002=
1=-=2-2=2-
2=2222220=2==001
1=00==11=-20-=2-2
1---0=-=
1-0==10-=22001
1=02=02-1=0111
1-=010-21-=21==02
10200-2=-=20120-2
1=-
10=122-
210-1=-=2011-0--1
2==-1=20
1=-=101-20=221-1
210
1-=-==-0-=02=---
1-=1=-=12=0
1-=0---12-0=
210-==1021=010=1
1=-212
11=1=-=2211=101222-
2=-==--=2
1=11-200--=
1120-
11=-0=221=0101=
11-1=-
1-12-2=0
1012-22=1-
20-122=-1=
1-100=0=101-0
20-1=1=0
1102=
21
10=20=11
1-=2001
1-20=12-0221102-==
1-1--010100=-1=
221002==2102-2=1
2012=121-22
110222002=01
212102-1=1=-211
210-=12
1=-1-0101=1-12
12--21=1
10=-12
100-122211=--2=
101102001
11011=-
211-0=-=0
1-2=01-1=
1-022-=00000
2==-0==2=--00=
10=--2000==
1---=--1-110-02
11-012
2==-2210-0
212
22-=-12111
2--=
2=2=12-100
10-12===0-
1==0=0=22012201
211-1--22

View File

@ -0,0 +1,13 @@
1=-0-2
12111
2=0=
21
2=01
111
20012
112
1=-1=
1-12
12
1=
122