Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Rotate deque in range solution in Clear category for Rotate Hole by Ilis
def rotate(state, pipe_numbers):
from collections import deque
pipes = deque(state, maxlen=len(state))
rotations = []
for r in range(len(pipes)):
if all([pipes[i] > 0 for i in pipe_numbers]):
rotations.append(r)
pipes.rotate()
return rotations
if __name__ == '__main__':
# print(rotate([1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1], [0, 1]))
# exit(0)
# 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"
April 22, 2019