2024 - Day 2 part 1

This commit is contained in:
kleph 2024-12-02 14:16:34 +01:00
parent d85a0511dc
commit e14adff2cd
3 changed files with 1037 additions and 0 deletions

31
2024/2/2.py Normal file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env python
# 2024 - Advent Of Code 2
# file = 'input_example.txt'
file = 'input.txt'
# pylint: disable=consider-using-with
input_lines = [line.strip('\n') for line in open(file, encoding="utf-8")]
safe = 0
for reports in input_lines:
levels = [ int(r) for r in reports.split(' ') ]
# print(f'{levels=}')
s_diff = 0 if levels[0] > levels[1] else 1
break_diff = False
for l in range(1, len(levels)):
diff = levels[l] - levels[l-1]
if abs(diff) > 3 or diff == 0:
break_diff = True
break
s_diff2 = 0 if levels[l] < levels[l-1] else 1
if s_diff ^ s_diff2 != 0:
# print("sign change")
break_diff = True
break
if not break_diff:
# print("safe")
safe += 1
print(f'{safe=}')

1000
2024/2/input.txt Normal file

File diff suppressed because it is too large Load diff

6
2024/2/input_example.txt Normal file
View file

@ -0,0 +1,6 @@
7 6 4 2 1
1 2 7 8 9
9 7 6 2 1
1 3 2 4 5
8 6 4 4 1
1 3 6 7 9