#advent of code 2020 #day 05 #examples = ["BFFFBBFRRR","FFFBBBFRRR","BBFFBBFRLL"]; def partitioner(instr, limLow, limHigh, splitLow, splitHigh): diff = limHigh - limLow + 1; if instr == "": return limLow; elif instr[0] == splitLow: return partitioner(instr[1:], limLow, limHigh-diff//2, splitLow, splitHigh); elif instr[0] == splitHigh: return partitioner(instr[1:], limLow+diff//2, limHigh, splitLow, splitHigh); p1 = 0; AllSeats = []; PuzzleInput = open("05.in","r"); for BoardingPass in PuzzleInput: BP = BoardingPass.replace("\n",""); row = partitioner(BP[:-3],0,127,"F","B"); col = partitioner(BP[-3:],0,7,"L","R"); seatID = row*8 + col; p1 = max(p1,seatID) AllSeats.append(seatID) PuzzleInput.close(); AllSeats = sorted(AllSeats); for n in range(1, len(AllSeats)): if AllSeats[n] - AllSeats[n-1] != 1: p2 = AllSeats[n-1] + 1; break; print("part 1 = ",p1); print("part 2 = ",p2);