Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def snafutodec(s):
- digits={"=": -2, "-": -1, "0": 0, "1": 1, "2": 2}
- n=0
- for i in range(len(s)):
- n+=5**i*digits[s[-i-1]]
- return n
- def dectosnafu(n):
- digits={-2: "=", -1: "-", 0: "0", 1: "1", 2: "2"}
- s=""
- while n!=0:
- s+=digits[(n+2)%5-2]
- n=(n-((n+2)%5-2))//5
- return s[::-1]
- inputfile="input25.txt"
- n=0
- with open(inputfile) as myfile:
- for line in myfile:
- n+=snafutodec(line.strip())
- print(dectosnafu(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement