Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Rotate Hole by marcelina.gorzelana
def rotate(state, pipe_numbers):
res = []
pipes = []
for e in state:
pipes.append(0)
for pipe in pipe_numbers:
pipes[pipe] = 1
print(pipes)
for i in range(len(state)):
p = 0
while p < len(pipes) and pipes[p] <= state[p]:
p+= 1
if p == len(pipes):
res.append(i)
tmp = state[len(state)-1]
for j in range(len(state) - 1, 0, -1):
state[j] = state[j-1]
state[0] = tmp
return res
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert rotate([1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1], [0, 1]) == [1, 8], "Example"
assert rotate([1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1], [0, 1, 2]) == [], "Mission impossible"
assert rotate([1, 0, 0, 0, 1, 1, 0, 1], [0, 4, 5]) == [0], "Don't touch it"
assert rotate([1, 0, 0, 0, 1, 1, 0, 1], [5, 4, 5]) == [0, 5], "Two cannonballs in the same pipe"
Dec. 7, 2016