1
0
This commit is contained in:
Nicolas Green 2024-12-03 11:13:11 -05:00
parent 1db5c69980
commit 0cf8b0b8bf
No known key found for this signature in database
3 changed files with 1045 additions and 0 deletions

1000
day2/input.txt Normal file

File diff suppressed because it is too large Load Diff

39
day2/main.py Normal file
View File

@ -0,0 +1,39 @@
safe_reports = 0
with open("input.txt", "r") as file_input:
for row in file_input:
report = list(map(int, row.split(" ")))
increasing = None
report_size = len(report)
safe_count = 0
for i in range(report_size):
if i == 0:
continue
current_number = report[i]
last_number = report[i-1]
difference = last_number - current_number
# Figure out if we're increasing or decreasing values in this row
if increasing is None:
if difference < 0 and (abs(difference) < 4):
increasing = True
elif difference > 0 and (abs(difference) < 4):
increasing = False
else:
break
# Once we figure it out just make sure we stay in our 3 pt range and don't
# decrease if we're supposed to be increasing or vice versa
elif increasing and (-4 < difference < 0):
safe_count += 1
elif not (increasing) and (0 < difference < 4):
safe_count += 1
else:
break
if safe_count == (report_size - 2):
safe_reports += 1
print(safe_reports)

6
day2/test_input.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