Skip to content

Commit

Permalink
[2022][day 25] add solution
Browse files Browse the repository at this point in the history
  • Loading branch information
IAjimi committed Dec 25, 2022
1 parent 44c3c2c commit f78ca92
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
58 changes: 58 additions & 0 deletions 2022/AOC25.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from typing import List

from _utils import read_input, timer, Solution


def process_input(filename: str) -> List[int]:
_input = read_input(filename)
return _input


def snafu_to_real(line: str) -> int:
num = 0

for i, char in enumerate(reversed(line)):
if char == "-":
val = -1
elif char == "=":
val = -2
else:
val = int(char)

num += val * (5 ** i)

return num


def real_to_snafu(num: int) -> str:
snafu = ""
while num:
remainder = num % 5
if remainder in (0, 1, 2):
snafu += str(remainder)
elif remainder == 3:
snafu += "=" # 2 away from 5
num += 2
elif remainder == 4:
snafu += "-" # 1 away from 5
num += 1
else:
assert Exception

num //= 5
return snafu[::-1]


@timer
def main(filename: str) -> Solution:
_input = process_input(filename)
part_1_sum = sum([snafu_to_real(line) for line in _input])
part_1_solution = real_to_snafu(part_1_sum)
part_2_solution = 0
return part_1_solution, part_2_solution


if __name__ == "__main__":
part_1_solution, part_2_solution = main("aoc25.txt")
print(f"PART 1: {part_1_solution}") # 2-==10===-12=2-1=-=0
print(f"PART 2: {part_2_solution}") # no part 2
1 change: 1 addition & 0 deletions 2022/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ This repository contains Python solutions to the 2022 edition of [Advent of Code
| [22](https://adventofcode.com/2022/day/22) | **Monkey Map** | [:star::star:](https://github.com/IAjimi/AdventOfCode/blob/master/2022/AOC22.py) |
| [23](https://adventofcode.com/2022/day/23) | **Unstable Diffusion** | [:star::star:](https://github.com/IAjimi/AdventOfCode/blob/master/2022/AOC23.py) |
| [24](https://adventofcode.com/2022/day/24) | **Blizzard Basin** | [:star::star:](https://github.com/IAjimi/AdventOfCode/blob/master/2022/AOC24.py) |
| [25](https://adventofcode.com/2022/day/25) | **Full of Hot Air** | [:star::star:](https://github.com/IAjimi/AdventOfCode/blob/master/2022/AOC25.py) |
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ This repository contains Python solutions to [Advent of Code puzzles](https://ad
| [2019](https://adventofcode.com/2019) | 2, 5, 7, 9, 12-15, 17-21, 23, 25 | [46 :star:](https://github.com/IAjimi/AdventOfCode2020/tree/master/2019) |
| [2020](https://adventofcode.com/2020) | 1-25 | [46 :star:](https://github.com/IAjimi/AdventOfCode2020/tree/master/2020) |
| [2021](https://adventofcode.com/2021) | 1-25 | [50 :star:](https://github.com/IAjimi/AdventOfCode2020/tree/master/2021) |
| [2022](https://adventofcode.com/2022) | 1-12 | [24 :star:](https://github.com/IAjimi/AdventOfCode2020/tree/master/2022) |
| [2022](https://adventofcode.com/2022) | 1-25 | [50 :star:](https://github.com/IAjimi/AdventOfCode2020/tree/master/2022) |

0 comments on commit f78ca92

Please sign in to comment.