|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- class SeatPass:
- def __init__(self, seatcode):
- self.getrow(seatcode[:7])
- self.getcol(seatcode[7:])
- self.getseat()
-
- def getrow(self, seatcode):
- seatcode = seatcode.replace('F', '0')
- seatcode = seatcode.replace('B', '1')
- self.row = int(seatcode, 2)
-
- def getcol(self, seatcode):
- seatcode = seatcode.replace('L', '0')
- seatcode = seatcode.replace('R', '1')
- self.col = int(seatcode, 2)
-
- def getseat(self):
- self.seatnum = (self.row * 8) + self.col
-
- def findOutlier(passes, minrow, maxrow):
- for i in range(1,len(passes)):
- p = passes[i]
- if p.row == minrow or p.row == maxrow:
- continue
- if p.seatnum + 1 == passes[i+1].seatnum:
- continue
- else:
- return p
- return False
-
- def main():
- with open('input5.txt') as file:
- lines = file.readlines()
- lines = [line.strip() for line in lines]
- passes = []
- maxseat = -1
- minrow = 999
- maxrow = -1
- for line in lines:
- p = SeatPass(line)
- passes.append(p)
- if p.seatnum > maxseat:
- maxseat = p.seatnum
- if p.row > maxrow:
- maxrow = p.row
- if p.row < minrow:
- minrow = p.row
- passes.sort(key=lambda x: x.seatnum)
- seats = sorted([p.seatnum for p in passes])
- print(seats)
- mypass = findOutlier(passes, minrow, maxrow)
- if mypass == False:
- print("I didn't find a pass meeting these criteria.")
- else:
- print(mypass.seatnum+1)
-
- print(f"The largest seat number I've seen is {maxseat}.")
-
- if __name__ == "__main__":
- main()
|