Hello,
I am stuck with one question, which is a looping question. I need to write an algorithm. I have the initial list as being {3, 2, 5, 1, 4}. Then, we can “cut” the list at 5 (consider the sublist {3,2,5}) and reverse it. Then, the list became {5, 2, 3, 1, 4}. Now we could decide to flip the whole list and obtain {4,1,3,2,5}.and so on. I need to loop the code until the code is in order which is {1,2,3,4,5}
This is what I have now
tl = {3, 2, 5, 1, 4};
For[
i = 4, i < 5, i++;
stry = tl;
newlist = Reverse[stry[[1 ;; 3]]];
sstry =
DeleteDuplicates[Flatten[AppendTo[newlist, stry[[1 ;; i]]]]]; |
Print[sstry]
Print[Reverse[sstry]]
]