Compare commits
No commits in common. "2023" and "2021" have entirely different histories.
40
1/main.py
40
1/main.py
|
@ -1,40 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
digit_map = {
|
|
||||||
'zero': 0,
|
|
||||||
'one': 1,
|
|
||||||
'two': 2,
|
|
||||||
'three': 3,
|
|
||||||
'four': 4,
|
|
||||||
'five': 5,
|
|
||||||
'six': 6,
|
|
||||||
'seven': 7,
|
|
||||||
'eight': 8,
|
|
||||||
'nine': 9
|
|
||||||
}
|
|
||||||
|
|
||||||
def find_digit_name(line):
|
|
||||||
for digit_name in digit_map.keys():
|
|
||||||
if line.startswith(digit_name):
|
|
||||||
return digit_map[digit_name]
|
|
||||||
return None
|
|
||||||
|
|
||||||
def find_digit(line, check_range):
|
|
||||||
for i in check_range:
|
|
||||||
if line[i].isdigit():
|
|
||||||
return int(line[i])
|
|
||||||
if (digit := find_digit_name(line[i:])) is not None:
|
|
||||||
return digit
|
|
||||||
|
|
||||||
|
|
||||||
# read input file
|
|
||||||
with open('input', 'r') as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
lines_sum = 0
|
|
||||||
for line in lines:
|
|
||||||
first_digit = find_digit(line, range(len(line)))
|
|
||||||
last_digit = find_digit(line, range(len(line) - 1, -1, -1))
|
|
||||||
num = str(first_digit) + str(last_digit)
|
|
||||||
lines_sum += int(num)
|
|
||||||
|
|
||||||
print(lines_sum)
|
|
20
1/solution.py
Executable file
20
1/solution.py
Executable file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
def get_positive_changes(values):
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
for i in range(1, len(values)):
|
||||||
|
if int(values[i - 1]) < int(values[i]):
|
||||||
|
count += 1
|
||||||
|
return count
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
f = open("input", "r")
|
||||||
|
values = f.readlines()
|
||||||
|
print('1. solution:', get_positive_changes(values))
|
||||||
|
|
||||||
|
new_values = []
|
||||||
|
for i in range(2, len(values)):
|
||||||
|
new_values.append(int(values[i]) + int(values[i-1]) + int(values[i-2]))
|
||||||
|
|
||||||
|
print('2. solution:', get_positive_changes(new_values))
|
Loading…
Reference in a new issue