Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Arrange a boarding list for passengers on a plane, starting from the rear (higher row numbers)
- # and boarding those furthest from an aisle first
- def makeBoardingList(aisles, seatcodes):
- aislePos = []
- # create a list of numeric values that represent the aisle positions
- for pair in aisles:
- aislePos.append((ord(pair[0]) + ord(pair[1])) / 2)
- output = []
- for seat in seatcodes:
- # First find the distance of this seat from each aisle
- # and choose the nearest aisle to this seat. This gives the primary sort key.
- alist = [abs(ord(seat[-1]) - pos) for pos in aislePos]
- minDist = min(alist)
- aisleValue = 10000 * alist.index(minDist)
- sequence = aisleValue + int(seat[:-1]) * 100 + minDist
- output.append((sequence, seat))
- return sorted(output, reverse=True)
- # 12 seats across. Aisles between seats C and D, and I and J
- aisleSeats = ["CD", "IJ"]
- inlist = ["7I", "8A", "2B", "7H", "6D", "6L", "4C", "8F", "1B", "7C", "10B",
- "6A", "7G", "7F", "8C", "11A", "9B", "6B", "6F", "6K", "9H", "10G"]
- outlist = makeBoardingList(aisleSeats, inlist)
- lastseq = 999999
- aisleNum = 1
- for tup in outlist:
- if (lastseq - tup[0]) > 5000: # test for change of aisle
- print("\nAisle", aisleNum)
- aisleNum += 1
- lastseq = tup[0]
- print(tup[1], end=" ")
- print()
- # Output:-
- # Aisle 1
- # 10G 9H 7G 7H 7I 6L 6K
- # Aisle 2
- # 11A 10B 9B 8F 8A 8C 7F 7C 6F 6A 6B 6D 4C 2B 1B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement