Compare commits
No commits in common. "d270ffbf1a4c43886f3d3dacc80dc1626f4db79d" and "2a65a36f09a436522d0ba2a712c124d35133509e" have entirely different histories.
d270ffbf1a
...
2a65a36f09
5 changed files with 2 additions and 1066 deletions
1000
day_01/input.txt
1000
day_01/input.txt
File diff suppressed because it is too large
Load diff
|
|
@ -1,39 +0,0 @@
|
||||||
#!/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()
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
1abc2
|
|
||||||
pqr3stu8vwx
|
|
||||||
a1b2c3d4e5f
|
|
||||||
treb7uchet
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
#!/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
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# https://adventofcode.com/2023/day/
|
# https://adventofcode.com/2022/day/
|
||||||
|
|
||||||
def get_lines(filename: str) -> list:
|
def get_lines(filename: str) -> list:
|
||||||
with open(filename, "r") as file:
|
with open(filename, "r") as file:
|
||||||
|
|
@ -8,8 +8,7 @@ def get_lines(filename: str) -> list:
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
lines = get_lines("test-input.txt")
|
pass
|
||||||
# lines = get_lines("input.txt")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue