|
|
@@ -0,0 +1,49 @@
|
|
|
+file = open('input.txt','r')
|
|
|
+
|
|
|
+passes = file.readlines()
|
|
|
+
|
|
|
+def getRow(code):
|
|
|
+ high = 127
|
|
|
+ low = 0
|
|
|
+ for c in code:
|
|
|
+ #print('Row Char: '+c)
|
|
|
+ if c == 'F':
|
|
|
+ high -=int( (high - low) / 2)
|
|
|
+ #print('high: '+str(high))
|
|
|
+ else:
|
|
|
+ low +=int( (high - low) / 2)
|
|
|
+ #print('low: '+str(low))
|
|
|
+ if code[-1] == 'F':
|
|
|
+ return high
|
|
|
+ else:
|
|
|
+ return low
|
|
|
+
|
|
|
+def getSeat(code):
|
|
|
+ high = 7
|
|
|
+ low = 0
|
|
|
+ for c in code:
|
|
|
+ #print('Row Char: '+c)
|
|
|
+ if c == 'R':
|
|
|
+ high -=int( (high - low) / 2)
|
|
|
+ #print('high: '+str(high))
|
|
|
+ else:
|
|
|
+ low +=int( (high - low) / 2)
|
|
|
+ #print('low: '+str(low))
|
|
|
+ if code[-1] == 'F':
|
|
|
+ return high
|
|
|
+ else:
|
|
|
+ return low
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+maxSeat = 0
|
|
|
+for p in passes:
|
|
|
+ row = getRow(p[:7])
|
|
|
+ column = getSeat(p[7:10])
|
|
|
+ seatID = row * 8 + column
|
|
|
+ #print('row: '+str(row))
|
|
|
+ #print('col: '+str(column))
|
|
|
+ #print('seat: '+str(seatID))
|
|
|
+ if seatID > maxSeat:
|
|
|
+ maxSeat = seatID
|
|
|
+print(str(maxSeat))
|