diff --git a/README.md b/README.md index 8133d20..02df006 100644 --- a/README.md +++ b/README.md @@ -8,19 +8,19 @@ for solutions in rust, refer to [rust repo][rustrepo] -| | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | +| | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | | - | - | - | - | - | - | - | - | - | -| 01 | [puzzle][201501p]
[✓][201501] | | | | | | | [puzzle][202201p]
[✓][202201] | -| 02 | [puzzle][201502p]
[✓][201502] | | | | | | | | -| 03 | [puzzle][201503p]
[✓][201503] | | | | | | | | -| 04 | [puzzle][201504p]
[✓][201504] | | | | | | | | -| 05 | [puzzle][201505p]
[✓][201505] | | | | | | | | -| 06 | [puzzle][201506p]
[✓][201506] | | | | | | | | -| 07 | [puzzle][201507p]
[✓][201507] | | | | | | | | -| 08 | [puzzle][201508p]
[✓][201508] | | | | | | | | -| 09 | [puzzle][201509p]
[✓][201509] | | | | | | | | -| 10 | [puzzle][201510p]
[✓][201510] | | | | | | | | -| 11 | [puzzle][201511p]
[✓][201511] | | | | | | | | +| 01 | [puzzle][201501p]
[✓][201501] | | | | | | | [puzzle][202201p]
[✓][202201] | [puzzle][202301p]
[✓][202301] | +| 02 | [puzzle][201502p]
[✓][201502] | | | | | | | | | +| 03 | [puzzle][201503p]
[✓][201503] | | | | | | | | | +| 04 | [puzzle][201504p]
[✓][201504] | | | | | | | | | +| 05 | [puzzle][201505p]
[✓][201505] | | | | | | | | | +| 06 | [puzzle][201506p]
[✓][201506] | | | | | | | | | +| 07 | [puzzle][201507p]
[✓][201507] | | | | | | | | | +| 08 | [puzzle][201508p]
[✓][201508] | | | | | | | | | +| 09 | [puzzle][201509p]
[✓][201509] | | | | | | | | | +| 10 | [puzzle][201510p]
[✓][201510] | | | | | | | | | +| 11 | [puzzle][201511p]
[✓][201511] | | | | | | | | | [201501]: https://github.com/Stegallo/adventofcode/blob/master/y_2015/day1.py [201501p]: https://adventofcode.com/2015/day/1 @@ -48,6 +48,9 @@ for solutions in rust, refer to [rust repo][rustrepo] [202201]: https://github.com/Stegallo/adventofcode/blob/master/y_2022/day1.py [202201p]: https://adventofcode.com/2022/day/1 +[202301]: https://github.com/Stegallo/adventofcode/blob/master/y_2023/day1.py +[202301p]: https://adventofcode.com/2023/day/1 + [rustrepo]: https://github.com/Stegallo/adventofcodeinrust ## to run the code diff --git a/y_1900/day0.py b/y_1900/day0.py index 2a6ff1b..23edd15 100644 --- a/y_1900/day0.py +++ b/y_1900/day0.py @@ -11,11 +11,9 @@ def _preprocess_input(self): self.__input_data = self._input_data[0] def _calculate_1(self): - x = self.__input_data - print(f"{x=}") + for x in self.__input_data: + print(f"{x}") return 0 def _calculate_2(self): - x = self.__input_data - print(f"{x=}") return 0 diff --git a/y_2023/day1.py b/y_2023/day1.py new file mode 100644 index 0000000..787b989 --- /dev/null +++ b/y_2023/day1.py @@ -0,0 +1,43 @@ +from common.aoc import AoCDay +from typing import List + +SPELLED = [ + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", +] + + +class Day(AoCDay): + def __init__(self, test=0): + super().__init__(__name__, test) + + def _preprocess_input(self): + self.__input_data = self._input_data[0] + + @staticmethod + def replace_word_with_number(input: str) -> str: + for c, k in enumerate(SPELLED): + input = input.replace(k, k + str(c + 1) + k) + return input + + @staticmethod + def calculate_calibration(input: List[str]) -> int: + s = 0 + for i in input: + j = [x for x in i if x.isnumeric()] + s += int(f"{j[0]}{j[-1]}") + return s + + def _calculate_1(self) -> int: + return self.calculate_calibration(self.__input_data) + + def _calculate_2(self) -> int: + new_input = [self.replace_word_with_number(i) for i in self.__input_data] + return self.calculate_calibration(new_input)