Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Rotate Hole by KarolinaK
def rot(state):
p1=state[0];p2=0
for i in range(1,len(state)):
p2=state[i];state[i]=p1;p1=p2;
state[0]=p1
return state
def rotate(state, pipe_numbers):
result=[]
for i in range(0,len(state)):
match=True
for j in pipe_numbers:
if(state[j]==0):
match=False
break
#print(i, match,result)
state=rot(state)
if(match==True):
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"
Oct. 26, 2016