Chewing gum for the 50g

The use of 'POS' in the last challenge gave me an idea, just type in these two programs:
<< 1 10 FOR i RAND 4 RND i E-6 * + NEXT 10 ->LIST SORT << E4 * FP
100 * R->I >> MAP >>
and store in 'ARRY'
then << 1 10 FOR j DUP j POS SWAP NEXT DROP 10 ->LIST R->I >> and
store in 'SHUFF'.
Then create a list with 'ARRY' to give a permutation of the first 10
(or however many you want) numbers. Then repeated use of 'SHUFF' returns a list of where the numbers were positioned in the first list, but then it toggles back to the original list, on and on, and it seems to work no matter how long the list. Can anyone offer the theory behind this? Thanks in advance. Glenn


'SHUFF' as programmed a bijective map that is its own inverse.


Thanks for your swift and sure response. I didn't know what I had stepped into, but it's amazing what a great resource these forum members can be (plus Wikipedia) - who needs school! I also noted which lists are invariant, like numbers in their "proper" positions
or pairs in "each other's" position, such as {6,7,4,3,5,1,2,8,10,9}.
Cheers, Glenn

Forum Jump: