diff options
Diffstat (limited to '2020/aoc2020-d05.py')
| -rw-r--r-- | 2020/aoc2020-d05.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/2020/aoc2020-d05.py b/2020/aoc2020-d05.py new file mode 100644 index 0000000..ffc6ffb --- /dev/null +++ b/2020/aoc2020-d05.py @@ -0,0 +1,33 @@ +#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); |
