Finishz day4, fu regex
This commit is contained in:
36
day5/day5.py
36
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:")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user