@@ -33,25 +33,31 @@ class GasStation:
33
33
cost : int
34
34
35
35
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 ]:
37
37
"""
38
- This function returns a list of gas stations.
38
+ This function returns a tuple of gas stations.
39
39
40
40
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
43
43
44
44
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)
46
54
"""
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
+ )
52
58
53
59
54
- def can_complete_journey (gas_quantities : list [ int ], costs : list [ int ]) -> int :
60
+ def can_complete_journey (gas_stations : tuple [ GasStation ]) -> int :
55
61
"""
56
62
This function returns the index from which to start the journey
57
63
in order to reach the end.
@@ -64,22 +70,19 @@ def can_complete_journey(gas_quantities: list[int], costs: list[int]) -> int:
64
70
start [int]: start index needed to complete the journey
65
71
66
72
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]) )
68
74
3
69
- >>> can_complete_journey([2, 3, 4], [3, 4, 3])
75
+ >>> can_complete_journey(get_gas_stations( [2, 3, 4], [3, 4, 3]) )
70
76
-1
71
-
72
77
"""
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 )
75
80
76
81
if total_gas < total_cost :
77
82
return - 1
78
83
79
84
start = 0
80
85
net = 0
81
- gas_stations = get_gas_stations (gas_quantities , costs )
82
-
83
86
for i , gas_station in enumerate (gas_stations ):
84
87
net += gas_station .gas_quantity - gas_station .cost
85
88
if net < 0 :
0 commit comments