The Museum of HP Calculators

HP Forum Archive 19

[ Return to Index | Top of Index ]

Generating Permutations
Message #1 Posted by Norman Dziedzic on 8 Dec 2010, 1:36 a.m.

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

      
Re: Generating Permutations
Message #2 Posted by Werner on 8 Dec 2010, 2:47 a.m.,
in response to message #1 by Norman Dziedzic

@ 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
\>>
            
Re: Generating Permutations
Message #3 Posted by Norman Dziedzic on 8 Dec 2010, 7:34 a.m.,
in response to message #2 by Werner

Brilliant Werner!

I'll be studying this for a while.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall