safe_reports = 0 with open("part1_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)