python-checkio/Incinerator/rotate-hole.py

27 lines
940 B
Python
Raw Normal View History

2020-01-08 17:32:09 +01:00
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"