From 12bd7dc36d793cbdcba4dfb6b7f66e0959909ced Mon Sep 17 00:00:00 2001 From: Nathan van Ofwegen Date: Mon, 7 Dec 2020 09:17:02 +0100 Subject: [PATCH] Finishz day4, fu regex --- day5/day5.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/day5/day5.py b/day5/day5.py index e7f8840..78ae9e1 100644 --- a/day5/day5.py +++ b/day5/day5.py @@ -1,24 +1,46 @@ -def getSeatID(boarding_pass): - row = boarding_pass.replace('F', '0').replace('B', '1')[0:7] - column = boarding_pass.replace('L', '0').replace('R', '1')[7:10] +def binary(str): + return int('0b' + str, 2) - row = (int('0b' + row, 2)) - column = (int('0b' + column, 2)) + +def getSeatID(boarding_pass): + row = binary(boarding_pass.replace('F', '0').replace('B', '1')[0:7]) + column = binary(boarding_pass.replace('L', '0').replace('R', '1')[7:10]) return (row * 8) + column def part1(): file = open("input.txt") - highest = 0 + + IDs = [] for line in file: - highest = max(getSeatID(line), highest) + IDs.append(getSeatID(line)) + + IDs.sort() + highest = max(IDs) print("Part 1: %d" % highest) def part2(): file = open("input.txt") + IDs = [] + for line in file: + IDs.append(getSeatID(line)) + + IDs.sort() + + for h in range(0, len(IDs) - 1): + val = IDs[h] + + l = IDs[h - 1] + h = IDs[h + 1] + + if l + 1 == val and val + 1 == h: + pass + else: + print("Huuh niet @ %d" % val) + print("Part 2:")