Skip to content

Commit

Permalink
Day 25: Full of Hot Air
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient committed Dec 25, 2022
1 parent 2e78c86 commit af46e21
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)|
45 changes: 45 additions & 0 deletions py/aoc2022/day25.py
Original file line number Diff line number Diff line change
@@ -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,)
1 change: 1 addition & 0 deletions py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit af46e21

Please sign in to comment.