Compare commits
4 commits
2a65a36f09
...
d270ffbf1a
| Author | SHA1 | Date | |
|---|---|---|---|
| d270ffbf1a | |||
| e268519cc5 | |||
| 3f21aab6d7 | |||
| a700461024 |
5 changed files with 1066 additions and 2 deletions
1000
day_01/input.txt
Normal file
1000
day_01/input.txt
Normal file
File diff suppressed because it is too large
Load diff
39
day_01/program.py
Executable file
39
day_01/program.py
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# https://adventofcode.com/2023/day/1
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def get_lines(filename: str) -> list:
|
||||
with open(filename, "r") as file:
|
||||
return [line.strip() for line in file.readlines()]
|
||||
|
||||
|
||||
def get_cal_val(line: str) -> int:
|
||||
found_first = False
|
||||
first = ""
|
||||
last = ""
|
||||
for test_char in line:
|
||||
if test_char.isdigit():
|
||||
if found_first:
|
||||
last = test_char
|
||||
else:
|
||||
first = test_char
|
||||
found_first = True
|
||||
if last == "":
|
||||
last = first
|
||||
return int(first + last)
|
||||
|
||||
|
||||
def main():
|
||||
# lines = get_lines("test-input.txt")
|
||||
lines = get_lines("input.txt")
|
||||
sum_cal_val = 0
|
||||
for line in lines:
|
||||
sum_cal_val += get_cal_val(line)
|
||||
print(f"Part 1: The sum of all calibration values is {sum_cal_val}.")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
4
day_01/test-input.txt
Normal file
4
day_01/test-input.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
||||
20
day_01/test_program.py
Executable file
20
day_01/test_program.py
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import program
|
||||
import unittest
|
||||
|
||||
|
||||
class TestThing(unittest.TestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def testGetCalVal(self):
|
||||
self.assertEqual(program.get_cal_val("a2c3"), 23)
|
||||
self.assertEqual(program.get_cal_val("1c3d"), 13)
|
||||
self.assertEqual(program.get_cal_val("3a2c3er"), 33)
|
||||
self.assertEqual(program.get_cal_val("1234567"), 17)
|
||||
self.assertEqual(program.get_cal_val("asdw3wemr"), 33)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# https://adventofcode.com/2022/day/
|
||||
# https://adventofcode.com/2023/day/
|
||||
|
||||
def get_lines(filename: str) -> list:
|
||||
with open(filename, "r") as file:
|
||||
|
|
@ -8,7 +8,8 @@ def get_lines(filename: str) -> list:
|
|||
|
||||
|
||||
def main():
|
||||
pass
|
||||
lines = get_lines("test-input.txt")
|
||||
# lines = get_lines("input.txt")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue