Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
simple solution in Clear category for Power Supply by Phil15
def power_supply(connections, power_plants):
connections = list(map(set, connections))
cities = set.union(*connections)
net = {i: {j for j in cities if {i, j} in connections} for i in cities}
while cities and power_plants:
city, range_value = power_plants.popitem()
cities.discard(city)
if range_value:
for n in net[city]:
power_plants[n] = max(power_plants.get(n, 0), range_value - 1)
return cities
Nov. 7, 2018