Generating Permutations



#4

I have been trying to figure out how to generate permutations of the elements in a list in user RPL w/ my 48gii. I know I can write a brute force generator but it seems there should be some elegant way to do this with P2C and/or C2P and perhaps DOLIST or DOSUB but I'm getting nowhere understanding the cycle notation stuff.

Am I whistling in the wind here or is there a way?

My simple test case is to generate all the permutations of the elements in the list {1 2 3 4}.

Thanks,
Norm


#5

@ 119.5 bytes, (48G) #48407d
\<<
{ {} } OVER SIZE 1 SWAP
FOR j
OVER j GET ADD
1
\<<
DUP +
1 j
START
TAIL DUP 1 j SUB SWAP
NEXT
DROP
\>>
DOSUBS
NEXT
SWAP DROP
\>>

#6

Brilliant Werner!

I'll be studying this for a while.


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP RPN stack permutations graph Xavier A. (Brazil) 14 409 05-20-2011, 06:54 PM
Last Post: exschr

Forum Jump: