I am trying to append a "P(i)" and a "D(i)" for every i.
li = []
for i in range(n):
li.append(f"p{i+1}")
li.append(f"d{i+1}")
Now, I am finding all the ways in which the list could be arranged such that for every i, P(i) always occurs before D(i)
perm = permutations(li)
For smaller n values, such as 2 or 3, I could just write:
k = list(perm)
for j in k:
if j.index("p1")<j.index("d1") and j.index("p2")<j.index("d2"):
count += 1
But for higher n values, in this way I will have to write expression starting from p1 to pn, which obviously isn't something I want to do.
In cases like these, where my test expression increases with the input, what should I do?
Aucun commentaire:
Enregistrer un commentaire