#advent of code 2024 #day 02 part1 = 0; ToCheck = []; f = open("02.in","r"); for l in f: levels = [int(lvl) for lvl in l.split()]; if (levels[1]-levels[0]) < 0: levels.reverse(); dMin = 4; dMax = 0; for i in range(1,len(levels)): d = levels[i] - levels[i-1]; dMin = min(dMin,d); dMax = max(dMax,d); if dMax <=3 and dMin >= 1: part1 += 1; else: ToCheck.append(levels); f.close(); correction = 0; for levels in ToCheck: isOK = False; for x in range(len(levels)): NewLevels = [levels[y] for y in range(len(levels)) if y !=x] for _ in ["n","r"]: #normal and reversed, reverse and the end of first iteration dMin = 4; dMax = 0; for i in range(1,len(NewLevels)): d = NewLevels[i] - NewLevels[i-1]; dMin = min(dMin,d); dMax = max(dMax,d); if dMax <=3 and dMin >= 1: isOK = True; NewLevels.reverse(); if isOK: correction += 1; part2 = part1 + correction; print("part 1 = ", part1); print("part 2 = ", part2);