You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
940 B

def rotate(state, pipe_numbers):
count = []
for i in range(len(state)):
last = state.pop()
state.insert(0, last)
is_good = True
for j in pipe_numbers:
if state[j] != 1:
is_good = False
break
if is_good:
if i+1 >= len(state):
count.append(0)
else:
count.append(i+1)
count.sort()
print(count)
return count
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"