-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlanding_holes.py
24 lines (17 loc) · 889 Bytes
/
landing_holes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# kpbochenek@gmail.com
check = lambda state, pos: all([state[i] == 1 for i in pos])
def rotate(state, pos):
if check(state, pos): result = [0]
else: result = []
for i in range(len(state)-1):
state = [state[-1]] + state[:-1]
if check(state, pos):
result.append(i+1)
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"
print("Code's finished? Earn rewards by clicking 'Check' to review your tests!")