Finishz day4, fu regex

This commit is contained in:
2020-12-07 09:17:02 +01:00
parent b8be3271a3
commit 12bd7dc36d

View File

@@ -1,24 +1,46 @@
def getSeatID(boarding_pass): def binary(str):
row = boarding_pass.replace('F', '0').replace('B', '1')[0:7] return int('0b' + str, 2)
column = boarding_pass.replace('L', '0').replace('R', '1')[7:10]
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 return (row * 8) + column
def part1(): def part1():
file = open("input.txt") file = open("input.txt")
highest = 0
IDs = []
for line in file: for line in file:
highest = max(getSeatID(line), highest) IDs.append(getSeatID(line))
IDs.sort()
highest = max(IDs)
print("Part 1: %d" % highest) print("Part 1: %d" % highest)
def part2(): def part2():
file = open("input.txt") 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:") print("Part 2:")