-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonkey.py
More file actions
30 lines (22 loc) · 1.11 KB
/
monkey.py
File metadata and controls
30 lines (22 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'''N monkeys are invited to a party where they start dancing. They dance in a circular formation, very similar to a Gujarati Garba or a Drum Circle. The dance requires the monkeys to constantly change positions after every 1 second.
The change of position is not random & you, in the audience, observe a pattern. Monkeys are very disciplined & follow a specific pattern while dancing.
Consider N = 6, and an array monkeys = {3,6,5,4,1,2}.
This array (1-indexed) is the dancing pattern. The value at monkeys[i], indicates the new of position of the monkey who is standing at the ith position.
Given N & the array monkeys[ ], find the time after which all monkeys are in the initial positions for the 1st time.'''
def groove(m):
temp = m
x = [0]*len(m)
count=0
while(x != m):
count += 1
x = [0]*len(m)
for i in range(len(m)):
x[m[i]-1] = temp[i]
temp = x
return(count)
t = int(input())
for _ in range(t):
n = int(input())
monkeys = list(map(int,input().split()))
result = groove(monkeys)
print(result)