Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day25(s):
- def from_snafu(text):
- return functools.reduce(lambda n, ch: n * 5 + '=-012'.index(ch) - 2, text, 0)
- def to_snafu(n):
- b = []
- while n != 0:
- n, mod = divmod(n + 2, 5)
- b.append('=-012'[mod])
- return ''.join(b[::-1])
- total = sum(from_snafu(line) for line in s.splitlines())
- return to_snafu(total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement