Advertisement
hhoppe

Advent of code 2022 day 25

Dec 24th, 2022
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. def day25(s):
  2.  
  3.   def from_snafu(text):
  4.     return functools.reduce(lambda n, ch: n * 5 + '=-012'.index(ch) - 2, text, 0)
  5.  
  6.   def to_snafu(n):
  7.     b = []
  8.     while n != 0:
  9.       n, mod = divmod(n + 2, 5)
  10.       b.append('=-012'[mod])
  11.     return ''.join(b[::-1])
  12.  
  13.   total = sum(from_snafu(line) for line in s.splitlines())
  14.   return to_snafu(total)
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement