I have this following code where I am trying to form an array 'opt'. Here, I am taking three possible values of 'pos_set' = [1, 2, 3] and in a similar manner, I can extend this. But, I just want a generalized code for any possible integer value of pos_set.
opt = []
if pos_set == 1:
for j in range(1, n):
opt.append([j])
elif pos_set == 2:
for j in range(1, n):
for k in range(j+1, n):
opt.append([j, k])
elif pos_set == 3:
for j in range(1, n):
for k in range(j+1, n):
for l in range(k+1, n):
opt.append([j, k, l])
For more clarity, I am doing this with the objective of collecting all possibilities if you roll an n-sided die and keep doing this as long as you keep rolling larger values.
For instance, if you roll a sequence 1-2-6-4, in this case after getting a 4 following a larger no. 6, you stop rolling. Similarly, if you roll a sequence 1-2-6-6, in this case you get a repeated 6 so you stop because it is not larger than your previous roll. I am considering cases before the smaller or same number occurs i.e., [1, 2, 6] in both cases.
If you guys can help me, I would be grateful.
[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [5, 6]]is this right output for pos_set =2 ?