We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 10cf8c2 commit a1d42faCopy full SHA for a1d42fa
1 file changed
2023/day_1.py
@@ -0,0 +1,35 @@
1
+def calibration_value(str_: str) -> int:
2
+ """
3
+
4
+ >>> calibration_value("1abc2")
5
+ 12
6
+ >>> calibration_value("pqr3stu8vwx")
7
+ 38
8
+ >>> calibration_value("a1b2c3d4e5f")
9
+ 15
10
+ >>> calibration_value("treb7uchet")
11
+ 77
12
13
+ digits = [char for char in str_ if char.isdigit()]
14
+ first_digit = digits[0]
15
+ last_digit = digits[-1]
16
17
+ two_digit_number = f"{first_digit}{last_digit}"
18
+ return int(two_digit_number)
19
20
21
+if __name__ == "__main__":
22
+ print("Provide puzzle input:")
23
24
+ strs = []
25
26
+ try:
27
+ while True:
28
+ strs.append(input())
29
30
+ except KeyboardInterrupt:
31
+ pass
32
33
+ print("Part 1:")
34
+ sum = sum(calibration_value(str_) for str_ in strs)
35
+ print(sum)
0 commit comments