HP Forums

Full Version: Generating Permutations
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

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

@ 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
\>>

Brilliant Werner!

I'll be studying this for a while.