Hackerland Radio Transmitters

  • + 0 comments
    def hackerlandRadioTransmitters(x, k):
        t=0 #number of transmitters
        ind=0 #our location in Hackerland
        while ind<max(x): #Loops through the cities in list x
            if ind+1 not in x:
                ind+=1 #This makes sure we don’t place transmitters in places where there are no houses
            else:
                while ind+k+1 not in x:
                    ind-=1 #This makes sure that the center is one of the houses
                t+=1 #Adds a transmitter
                ind+=(2*k+1) #skips all the locations where the transmitter is reached
        return t #returns the amount of of transmitters