main.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. file = open('input.txt','r')
  2. passes = file.readlines()
  3. def getRow(code):
  4. high = 127
  5. low = 0
  6. for c in code:
  7. print('Row Char: '+c)
  8. if c == 'F':
  9. high -=int( (high - low + 1) / 2)
  10. else:
  11. low +=int( (high - low + 1 ) / 2)
  12. print('low: ' + str(low) + ' high: ' + str(high))
  13. return low
  14. def getSeat(code):
  15. high = 7
  16. low = 0
  17. for c in code:
  18. print('Row Char: '+c)
  19. if c == 'L':
  20. high -=int( (high - low +1) / 2)
  21. else:
  22. low +=int( (high - low + 1) / 2)
  23. print('low: ' + str(low) + ' high: ' + str(high))
  24. return low
  25. maxSeat = 0
  26. seats = []
  27. #passes = ['FBFBBFFRLR','BFFFBBFRRR','FFFBBBFRRR','BBFFBBFRLL']
  28. for p in passes:
  29. row = getRow(p[:7])
  30. column = getSeat(p[7:10])
  31. seatID = (row * 8) + column
  32. seats.append(seatID)
  33. print(p)
  34. print('row: '+str(row))
  35. print('col: '+str(column))
  36. print('seat: '+str(seatID))
  37. if seatID > maxSeat:
  38. maxSeat = seatID
  39. last = 0
  40. preLast = 0
  41. seats = sorted(set(seats), key = lambda ele: seats.count(ele))
  42. #seats.sort()
  43. for s in seats:
  44. print(str(last) + ' vs ' + str(s))
  45. if s - 1 != last and s == last + 2:
  46. print('hole between ' + str(s) + ' and ' + str(last))
  47. preLast = last
  48. last = int(s)
  49. #print(str(maxSeat))