day25 finished

This commit is contained in:
Ruediger Ludwig 2022-12-28 15:39:38 +01:00
parent c2ebf9dc84
commit 56764331a4
6 changed files with 247 additions and 25 deletions

View file

@ -0,0 +1,33 @@
from __future__ import annotations
from typing import Iterator
day_num = 25
def part1(lines: Iterator[str]) -> str:
snafu = sum(from_snafu(line) for line in lines)
return to_snafu(snafu)
def part2(lines: Iterator[str]) -> None:
return None
SNAFU = "=-012"
def from_snafu(line: str) -> int:
result = 0
for char in line:
result = result * 5 + SNAFU.index(char) - 2
return result
def to_snafu(number: int) -> str:
result = ""
while number > 0:
mod = (number + 2) % 5
result = SNAFU[mod] + result
number = (number - mod + 2) // 5
return result