-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .day1 import Day1 | ||
|
||
days = {1: Day1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from advent.day import Day | ||
|
||
|
||
class Day1(Day): | ||
year = 2023 | ||
day = 1 | ||
|
||
def _part1(self): | ||
return self._get_calibration_sum(self.input().splitlines()) | ||
|
||
def _get_calibration_sum(self, lines: [str]) -> int: | ||
if len(lines) < 1: | ||
raise ValueError(f"No lines were passed: {lines}") | ||
|
||
else: | ||
sum = 0 | ||
for line in lines: | ||
sum += self._get_calibration_values(line) | ||
return sum | ||
|
||
def _get_calibration_values(self, line: str) -> int: | ||
return int( | ||
self._get_calibration_digit(line) + self._get_calibration_digit(line, True) | ||
) | ||
|
||
def _get_calibration_digit(self, line: str, reverse: bool = False) -> str: | ||
chars = list(line) | ||
|
||
if reverse: | ||
for char in chars[::-1]: | ||
if char.isdigit(): | ||
return char | ||
|
||
else: | ||
for char in chars: | ||
if char.isdigit(): | ||
return char | ||
|
||
raise ValueError(f"Did not find a digit in line: {line}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.