Advertisement
acclivity

pyBoardingList2

Nov 11th, 2021
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # Arrange a boarding list for passengers on a plane, starting from the rear (higher row numbers)
  2. # and boarding those furthest from an aisle first
  3.  
  4. def makeBoardingList(aisles, seatcodes):
  5.     aislePos = []
  6.     # create a  list of numeric values that represent the aisle positions
  7.     for pair in aisles:
  8.         aislePos.append((ord(pair[0]) + ord(pair[1])) / 2)
  9.  
  10.     output = []
  11.     for seat in seatcodes:
  12.         # First find the distance of this seat from each aisle
  13.         # and choose the nearest aisle to this seat. This gives the primary sort key.
  14.         alist = [abs(ord(seat[-1]) - pos) for pos in aislePos]
  15.         minDist = min(alist)
  16.         aisleValue = 10000 * alist.index(minDist)
  17.         sequence = aisleValue + int(seat[:-1]) * 100 + minDist
  18.         output.append((sequence, seat))
  19.  
  20.     return sorted(output, reverse=True)
  21.  
  22.  
  23. # 12 seats across. Aisles between seats C and D, and I and J
  24. aisleSeats = ["CD", "IJ"]
  25. inlist = ["7I", "8A", "2B", "7H", "6D", "6L", "4C", "8F", "1B", "7C", "10B",
  26.           "6A", "7G", "7F", "8C", "11A", "9B", "6B", "6F", "6K", "9H", "10G"]
  27.  
  28. outlist = makeBoardingList(aisleSeats, inlist)
  29. lastseq = 999999
  30. aisleNum = 1
  31. for tup in outlist:
  32.     if (lastseq - tup[0]) > 5000:       # test for change of aisle
  33.         print("\nAisle", aisleNum)
  34.         aisleNum += 1
  35.     lastseq = tup[0]
  36.     print(tup[1], end="  ")
  37. print()
  38.  
  39. # Output:-
  40. # Aisle 1
  41. # 10G  9H  7G  7H  7I  6L  6K
  42. # Aisle 2
  43. # 11A  10B  9B  8F  8A  8C  7F  7C  6F  6A  6B  6D  4C  2B  1B
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement