diff --git a/README.md b/README.md index 7ed2186..9fe59b8 100644 --- a/README.md +++ b/README.md @@ -30,4 +30,4 @@ Development occurs in language-specific directories: |[Day22.hs](hs/src/Day22.hs)|[Day22.kt](kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day22.kt)|[day22.py](py/aoc2022/day22.py)|[day22.rs](rs/src/day22.rs)| |[Day23.hs](hs/src/Day23.hs)|[Day23.kt](kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day23.kt)|[day23.py](py/aoc2022/day23.py)|[day23.rs](rs/src/day23.rs)| |[Day24.hs](hs/src/Day24.hs)|[Day24.kt](kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day24.kt)|[day24.py](py/aoc2022/day24.py)|[day24.rs](rs/src/day24.rs)| -|[Day25.hs](hs/src/Day25.hs)|[Day25.kt](kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day25.kt)| +|[Day25.hs](hs/src/Day25.hs)|[Day25.kt](kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day25.kt)|[day25.py](py/aoc2022/day25.py)| diff --git a/py/aoc2022/day25.py b/py/aoc2022/day25.py new file mode 100644 index 0000000..6d60f8d --- /dev/null +++ b/py/aoc2022/day25.py @@ -0,0 +1,45 @@ +""" +Day 25: Full of Hot Air +""" + +SAMPLE_INPUT = [ + "1=-0-2", + "12111", + "2=0=", + "21", + "2=01", + "111", + "20012", + "112", + "1=-1=", + "1-12", + "12", + "1=", + "122", +] + + +def _unsnafu(snafu): + number = 0 + for char in snafu: + number = 5 * number + (-2 if char == "=" else -1 if char == "-" else int(char)) + return number + + +def _snafu(number): + snafu = "" + while number: + snafu += "012=-"[number % 5] + number = (number + 2) // 5 + return snafu[::-1] + + +def part1(lines): + """ + >>> part1(SAMPLE_INPUT) + '2=-1=0' + """ + return _snafu(sum(_unsnafu(line.rstrip()) for line in lines)) + + +parts = (part1,) diff --git a/py/pyproject.toml b/py/pyproject.toml index 01b3625..ec5b006 100644 --- a/py/pyproject.toml +++ b/py/pyproject.toml @@ -56,6 +56,7 @@ day21 = "aoc2022.day21:parts" day22 = "aoc2022.day22:parts" day23 = "aoc2022.day23:parts" day24 = "aoc2022.day24:parts" +day25 = "aoc2022.day25:parts" [tool.black] target_version = ["py311"]