2024-12-02 00:14:08 -06:00

86 lines
2.4 KiB
Python

with open('puzzle.txt', 'r') as f:
lines = f.read().splitlines()
segmented_report = []
for line in lines:
segmented_report.append([int(x) for x in line.split(' ')])
safe_reports = 0
bad_reports = 0
for report in segmented_report:
print(f'Loop began {report}')
if report[0] > report[-1]:
good_report = False
for i in range(len(report) - 1):
if 3 >= report[i] - report[i + 1] >= 1:
good_report = True
else:
good_report = False
break
if good_report:
print(f'safe {report}')
safe_reports += 1
else:
for x in range(len(report)):
if good_report:
break
temp_report = report.copy()
temp_report.pop(x)
for i in range(len(temp_report) - 1):
if 3 >= temp_report[i] - temp_report[i + 1] >= 1:
good_report = True
else:
good_report = False
break
if good_report:
print(f'safe {temp_report}')
safe_reports += 1
else:
print(f'bad {report}')
bad_reports += 1
elif report[0] < report[-1]:
good_report = False
for i in range(len(report) - 1):
if 3 >= report[i + 1] - report[i] >= 1:
good_report = True
else:
good_report = False
break
if good_report:
print(f'safe {report}')
safe_reports += 1
else:
for x in range(len(report)):
if good_report:
break
temp_report = report.copy()
temp_report.pop(x)
for i in range(len(temp_report) - 1):
if 3 >= temp_report[i + 1] - temp_report[i] >= 1:
good_report = True
else:
good_report = False
break
if good_report:
print(f'safe {temp_report}')
safe_reports += 1
else:
print(f'bad {report}')
bad_reports += 1
else:
bad_reports += 1
print(f'bad_reports {bad_reports}')
print(f'safe_reports {safe_reports}')