SHARE
TWEET

Untitled

a guest Feb 20th, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class AirCraftCabinLoading:
  2.     def __init__(self):
  3.         self.aircraft=[]
  4.         for i in range(10):
  5.             self.aircraft.push({
  6.                 "unavailableSeatsRight":0,
  7.                 "unavailableSeatsLeft":0,
  8.                 "takenSeatsRight":0,
  9.                 "takenSeatsLeft":0,
  10.                 "passengerOrGroupIds":{}
  11.             })
  12.  
  13.     def _place_passengers_in_row(self,row,numberOfPassengers,id):
  14.         for i in range(numberOfPassengers):
  15.             if (row["takenSeatsRight"]>row["takenSeatsLeft"]):
  16.                 row["takenSeatsLeft"]+=1
  17.             else:
  18.                 row["takenSeatsRight"]+=1
  19.         row["passengerOrGroupIds"][id]=numberOfPassengers
  20.  
  21.     def _remove_passengers_in_row(self,row,id):
  22.         numberOfPassengers=row["passengerOrGroupIds"][id]
  23.         for i in range(numberOfPassengers):
  24.             if (row["takenSeatsRight"]>row["takenSeatsLeft"]):
  25.                 row["takenSeatsLeft"] -= 1
  26.             else:
  27.                 row["takenSeatsRight"]-=1
  28.  
  29.  
  30.     def place_passengers(self,numberOfPassengers,passenger_or_group_id):
  31.         if (numberOfPassengers>4)
  32.             raise Exception("No more than 4 passengers are allowed in a group");
  33.         for i in [[5,4],[6,3],[7,2],[8,1],[9,0]]:
  34.             first_row=self.aircraft[i[0]]
  35.             second_row=self.aircraft[i[1]]
  36.             seats_available_first_row=4-first_row["takenSeatsLeft"]-first_row["takenSeatsLeft"]-first_row["unavailableSeatsRight"]-first_row["unavailableSeatsLeft"]
  37.             seats_available_second_row=4-second_row["takenSeatsLeft"]-second_row["takenSeatsLeft"]-second_row["unavailableSeatsRight"]-second_row["unavailableSeatsLeft"]
  38.             if (numberOfPassengers<=seats_available_first_row and numberOfPassengers<=seats_available_second_row):
  39.                 if (seats_available_first_row<seats_available_second_row):
  40.                     self._place_passengers_in_row(first_row,numberOfPassengers,passenger_or_group_id)
  41.                 else:
  42.                     self._place_passengers_in_row(second_row,numberOfPassengers,passenger_or_group_id)
  43.             elif (numberOfPassengers<=seats_available_first_row)
  44.                 self._place_passengers_in_row(first_row, numberOfPassengers, passenger_or_group_id)
  45.             elif (numberOfPassengers<=seats_available_second_row):
  46.                 self._place_passengers_in_row(second_row, numberOfPassengers, passenger_or_group_id)
  47.  
  48.     def remove_passengers(self,passenger_or_group_id):
  49.         for row in self.aircraft:
  50.             if (row["passengerOrGroupIds"][passenger_or_group_id]):
  51.                 self._remove_passengers_in_row(row,passenger_or_group_id)
  52.  
  53.     def get_n_of_unavailable_seats(self):
  54.         n=0
  55.         for row in self.aircraft:
  56.             n+=row["takenSeatsLeft"]+row["takenSeatsLeft"]+row["unavailableSeatsRight"]+row["unavailableSeatsLeft"]
  57.         return n
  58.  
  59.     def get_n_of_avaiable_seats(self):
  60.         return 40-self.get_n_of_unavailable_seats()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top