summaryrefslogtreecommitdiff
path: root/2020/aoc2020-d05.py
diff options
context:
space:
mode:
authorblenovo <bk@gmail.com>2025-07-16 18:55:48 +0200
committerblenovo <bk@gmail.com>2025-07-16 18:55:48 +0200
commit99a7d62c30069a5ffe2210a72c7cf81e76a1f241 (patch)
tree71c5c529b7f2fda9b5b5897a56a4ef3199400709 /2020/aoc2020-d05.py
parent15662865f0886209d871a7225bfc62cffd2e0783 (diff)
summertime warmup session with 2020 event
Diffstat (limited to '2020/aoc2020-d05.py')
-rw-r--r--2020/aoc2020-d05.py33
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);