@@ -33,25 +33,31 @@ class GasStation:
3333    cost : int 
3434
3535
36- def  get_gas_stations (gas_quantities : list [int ], costs : list [int ]) ->  list [GasStation ]:
36+ def  get_gas_stations (gas_quantities : list [int ], costs : list [int ]) ->  tuple [GasStation ]:
3737    """ 
38-     This function returns a list  of gas stations. 
38+     This function returns a tuple  of gas stations. 
3939
4040    Args: 
41-         gas_quantities [list] : Amount of gas available at each station 
42-         cost [list] : The cost of gas required to move from a station to the next 
41+         gas_quantities: Amount of gas available at each station 
42+         costs : The cost of gas required to move from a station to the next 
4343
4444    Returns: 
45-         gas_stations [list]: a list of gas stations 
45+         A tuple of gas stations 
46+      
47+     >>> gas_stations = get_gas_stations([1, 2, 3, 4, 5], [3, 4, 5, 1, 2]) 
48+     >>> len(gas_stations) 
49+     5 
50+     >>> gas_stations[0] 
51+     GasStation(gas_quantity=1, cost=3) 
52+     >>> gas_stations[-1] 
53+     GasStation(gas_quantity=5, cost=2) 
4654    """ 
47-     gas_stations  =  [
48-         GasStation (gas_quantity , cost )
49-         for  (gas_quantity , cost ) in  zip (gas_quantities , costs )
50-     ]
51-     return  gas_stations 
55+     return  tuple (
56+         GasStation (quantity , cost ) for  quantity , cost  in  zip (gas_quantities , costs )
57+     )
5258
5359
54- def  can_complete_journey (gas_quantities :  list [ int ],  costs :  list [ int ]) ->  int :
60+ def  can_complete_journey (gas_stations :  tuple [ GasStation ]) ->  int :
5561    """ 
5662    This function returns the index from which to start the journey 
5763    in order to reach the end. 
@@ -64,22 +70,19 @@ def can_complete_journey(gas_quantities: list[int], costs: list[int]) -> int:
6470        start [int]: start index needed to complete the journey 
6571
6672    Examples: 
67-     >>> can_complete_journey([1, 2, 3, 4, 5], [3, 4, 5, 1, 2]) 
73+     >>> can_complete_journey(get_gas_stations( [1, 2, 3, 4, 5], [3, 4, 5, 1, 2]) ) 
6874    3 
69-     >>> can_complete_journey([2, 3, 4], [3, 4, 3]) 
75+     >>> can_complete_journey(get_gas_stations( [2, 3, 4], [3, 4, 3]) ) 
7076    -1 
71- 
7277    """ 
73-     total_gas  =  sum (gas_quantities )
74-     total_cost  =  sum (costs )
78+     total_gas  =  sum (gas_station . gas_quantity   for   gas_station   in   gas_stations )
79+     total_cost  =  sum (gas_station . cost   for   gas_station   in   gas_stations )
7580
7681    if  total_gas  <  total_cost :
7782        return  - 1 
7883
7984    start  =  0 
8085    net  =  0 
81-     gas_stations  =  get_gas_stations (gas_quantities , costs )
82- 
8386    for  i , gas_station  in  enumerate (gas_stations ):
8487        net  +=  gas_station .gas_quantity  -  gas_station .cost 
8588        if  net  <  0 :
0 commit comments