generated from public/aoc_template
48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
NUMBERS = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(142, "input1_test1"),
|
|
(53386, "input1"),
|
|
],
|
|
[
|
|
(281, "input1_test2"),
|
|
(53312, "input1"),
|
|
],
|
|
]
|
|
|
|
def getCalibrationSum(self, translate: bool = False) -> int:
|
|
calibration_sum = 0
|
|
for line in self.getInput():
|
|
dig = ""
|
|
while line:
|
|
if translate:
|
|
for i, n in enumerate(NUMBERS):
|
|
if line.startswith(n):
|
|
dig += str(i)
|
|
|
|
if line[0].isdigit():
|
|
dig += line[0]
|
|
|
|
line = line[1:]
|
|
|
|
calibration_sum += int(dig[0]) * 10 + int(dig[-1])
|
|
|
|
return calibration_sum
|
|
|
|
def part1(self) -> Any:
|
|
return self.getCalibrationSum()
|
|
|
|
def part2(self) -> Any:
|
|
return self.getCalibrationSum(True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
day = Day(2023, 1)
|
|
day.run(verbose=True)
|