Skip to content
Snippets Groups Projects
Verified Commit d60a100c authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Cleaned up 2023 Day 01

parent 832728e4
No related branches found
No related tags found
No related merge requests found
......@@ -5,14 +5,15 @@ from ImportData import import_data
day: int = 1
# sample_data: List[str] = '''
# 1abc2
# pqr3stu8vwx
# a1b2c3d4e5f
# treb7uchet
# '''.split('\n')[1:-1]
sample_data: List[str] = '''
sample_data: List[List[str]] = [
'''
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
'''.split('\n')[1:-1]
,
'''
two1nine
eightwothree
abcone2threexyz
......@@ -21,31 +22,12 @@ xtwone3four
zoneight234
7pqrstsixteen
'''.split('\n')[1:-1]
]
data_structure: type = List[str]
data_structure: type = List[int]
def parse_data(data: List[str]) -> data_structure:
return data
def part1(data: data_structure) -> int:
values: List[int] = []
for datum in data:
first_digit: Optional[int] = None
last_digit: int = 0
for character in datum:
if character.isdigit():
first_digit = int(character) if first_digit is None else first_digit
last_digit = int(character)
if first_digit is None:
first_digit = 0
last_digit = 0
values.append(10 * first_digit + last_digit)
return functools.reduce(lambda a, b: a + b, values)
def part2(data: data_structure) -> int:
digit_names: Dict[str, int] = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5,
'six': 6, 'seven': 7, 'eight': 8, 'nine': 9, 'zero': 0}
values: List[int] = []
......@@ -67,11 +49,20 @@ def part2(data: data_structure) -> int:
first_digit = 0
last_digit = 0
values.append(10 * first_digit + last_digit)
return functools.reduce(lambda a, b: a + b, values)
return values
def part1(data: data_structure) -> int:
return functools.reduce(lambda a, b: a + b, data)
def part2(data: data_structure) -> int:
return functools.reduce(lambda a, b: a + b, data)
if __name__ == '__main__':
production_ready = True
raw_data = import_data(day) if production_ready else sample_data
raw_data = import_data(day) if production_ready else sample_data[0]
print(part1(parse_data(raw_data)))
raw_data = import_data(day) if production_ready else sample_data[1]
print(part2(parse_data(raw_data)))
......@@ -4,9 +4,9 @@ from ImportData import import_data
day: int = X
sample_data: List[str] = [
]
sample_data: List[str] = '''
...
'''.split('\n')[1:-1]
data_structure: type = Y
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment