Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Rotate Hole by Lachesis_132296
def position(state, pipe_numbers):
for i in pipe_numbers:
if state[i] == 0:
return False
return True
def move(state):
new = state[:]
n = len(state)
new[0] = state[n-1]
for i in range(1, n):
new[i] = state[i-1]
return new
#print(position([1, 0, 0, 0, 1, 1, 0, 1], [0, 4, 5]))
#print(move([1, 0, 0, 0, 1, 1, 0, 1]))
def rotate(state, pipe_numbers):
n = len(state)
result = []
if position(state, pipe_numbers):
result.append(0)
for i in range(1, n):
state = move(state)
if position(state, pipe_numbers):
result.append(i)
return result
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"
Nov. 19, 2016