CoCalc Shared FilesCyclesAvoiding.sagewsOpen in CoCalc with one click!
Author: Sarah Wolff
Views : 8
P=Permutations(4) Q=[] for k in [0..len(P)-1]: if P[k][0]==1: Q.append(P[k]) print Q
[[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2]]
has123=[] for l in [0..len(Q)-1]: for i in [0..len(Q[l])-1]: for j in [1..len(Q[l])-1]: if Q[l][Mod(i+j,len(Q[l]))]>Q[l][i]: #for each cycle, Q[l], in the list of cycles, go around the cycle by fixing one element, the ith term. Find each element that is greater than the ith term, going around the cycle until you get back to the ith term for k in [1..len(Q[l])-j-1]: #go around the rest of the cycle and check the final remaining terms if Q[l][Mod(i+j+k,len(Q[l]))]>Q[l][Mod(i+j,len(Q[l]))]: #print Q[l], 'has 123', Q[l][i],Q[l][Mod(i+j,len(Q[l]))],Q[l][Mod(i+j+k,len(Q[l]))] has123.append(Q[l]) uniq(has123) len(uniq(has123))
[[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3]] 5
has132=[] for l in [0..len(Q)-1]: for i in [0..len(Q[l])-1]: for j in [1..len(Q[l])-1]: if Q[l][Mod(i+j,len(Q[l]))]>Q[l][i]: #for each cycle, Q[l], in the list of cycles, go around the cycle by fixing one element, the ith term. Find each element that is greater than the ith term, going around the cycle until you get back to the ith term for k in [1..len(Q[l])-j-1]: #go around the rest of the cycle and check the final remaining terms if Q[l][Mod(i+j+k,len(Q[l]))]>Q[l][i]: if Q[l][Mod(i+j+k,len(Q[l]))]<Q[l][Mod(i+j,len(Q[l]))]: #print Q[l], 'has 132', Q[l][i],Q[l][Mod(i+j,len(Q[l]))],Q[l][Mod(i+j+k,len(Q[l]))] has132.append(Q[l]) uniq(has132) len(uniq(has132))
[[1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2]] 5
has213=[] for l in [0..len(Q)-1]: for i in [0..len(Q[l])-1]: for j in [1..len(Q[l])-1]: if Q[l][Mod(i+j,len(Q[l]))]<Q[l][i]: #for each cycle, Q[l], in the list of cycles, go around the cycle by fixing one element, the ith term. Find each element that is greater than the ith term, going around the cycle until you get back to the ith term for k in [1..len(Q[l])-j-1]: #go around the rest of the cycle and check the final remaining terms if Q[l][Mod(i+j+k,len(Q[l]))]>Q[l][i]: if Q[l][Mod(i+j+k,len(Q[l]))]>Q[l][Mod(i+j,len(Q[l]))]: print Q[l], 'has 213', Q[l][i],Q[l][Mod(i+j,len(Q[l]))],Q[l][Mod(i+j+k,len(Q[l]))] has213.append(Q[l]) uniq(has213) len(uniq(has213))
[1, 2, 4, 3] has 213 3 1 4 [1, 2, 4, 3] has 213 3 2 4 [1, 3, 2, 4] has 213 3 2 4 [1, 3, 2, 4] has 213 2 1 3 [1, 3, 4, 2] has 213 2 1 3 [1, 3, 4, 2] has 213 2 1 4 [1, 4, 2, 3] has 213 2 1 4 [1, 4, 2, 3] has 213 3 1 4 [1, 4, 3, 2] has 213 3 2 4 [1, 4, 3, 2] has 213 3 1 4 [1, 4, 3, 2] has 213 2 1 4 [1, 4, 3, 2] has 213 2 1 3 [[1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2]] 5