From 99a7d62c30069a5ffe2210a72c7cf81e76a1f241 Mon Sep 17 00:00:00 2001 From: blenovo Date: Wed, 16 Jul 2025 18:55:48 +0200 Subject: summertime warmup session with 2020 event --- 2020/aoc2020-d05.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 2020/aoc2020-d05.py (limited to '2020/aoc2020-d05.py') 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); -- cgit v1.2.3