Skip to content

Commit bc082d3

Browse files
committed
Create mapping from digits names to numbers
1 parent ff75b72 commit bc082d3

File tree

1 file changed

+6
-7
lines changed
  • puzzles/solutions/2023/d01

1 file changed

+6
-7
lines changed

puzzles/solutions/2023/d01/p2.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
import p1
44

55

6-
TRANSLATION_TABLE = str.maketrans(
7-
dict(
8-
zip(
9-
("one", "two", "three", "four", "five", "six", "seven", "eight", "nine"),
10-
range(1, 10),
11-
)
6+
DIGITS_NAMES_TO_NUMBERS = dict(
7+
zip(
8+
("one", "two", "three", "four", "five", "six", "seven", "eight", "nine"),
9+
(map(str, range(1, 10))),
1210
)
1311
)
1412

1513

1614
def get_answer(input_text: str):
17-
raise NotImplementedError
15+
input_text = input_text.translate(DIGITS_NAMES_TO_NUMBERS_TRANSLATION_TABLE)
16+
return p1.calculate_calibration_values_sum(input_text)
1817

1918

2019
if __name__ == "__main__":

0 commit comments

Comments
 (0)