Any's xHarbour function support it?

Post Reply
User avatar
richard-service
Posts: 807
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan
Has thanked: 1 time
Contact:

Any's xHarbour function support it?

Post by richard-service »

Hi
I have a 123 number
What's function that let me show these
123,132,213,231,312,321
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: Any's xHarbour function support it?

Post by cnavarro »

richard-service wrote:Hi
I have a 123 number
What's function that let me show these
123,132,213,231,312,321


Please, test

Code: Select all | Expand


//----------------------------------------------------------------------------//

// Program: Permutations of string -> number of permutations = factorial len( string )
// Date:    08/02/2010
// Autor:   Cristobal Navarro
//----------------------------------------------------------------------------//

#include "fivewin.ch"

Static cString
Static aString
Static aTmpString

Function Main()

    local x
    aString      := {}
    aTmpString   := {}
    cString      := "ABC"
    SetArray()
    Permutations( 1, Len( cString ) )
    ? Len( aString )
    //AEVal( aString, { | a | a := Val( a ) } )
    XBrowse( aString )          //Add 23/05/2016
Return nil

//----------------------------------------------------------------------------//

Function Permutations( nIni, nLen )

   local x
   if nIni <> nLen
      For x = nIni to nLen
         SwapArray( nIni, x )
         Permutations( nIni + 1, nLen )
         SwapArray( nIni, x )          
      Next x
   else
      AAdd( aString, SetString() )
   endif

Return nil

//----------------------------------------------------------------------------//

Function SwapArray( nIni, nAct )

    local cTemp
    cTemp  := aTmpString[ nIni ]
    aTmpString[ nIni ] := aTmpString[ nAct ]
    aTmpString[ nAct ] := cTemp

Return nil

//----------------------------------------------------------------------------//

Function SetArray()

   local x
   For x = 1 to Len( cString )
       AAdd( aTmpString, Substr( cString, x, 1 ) )
   Next x

Return nil

//----------------------------------------------------------------------------//

Function SetString()

   local x
   local cCad   := ""
   For x = 1 to Len( aTmpString )
      cCad += aTmpString[ x ]
   Next x

Return cCad

//----------------------------------------------------------------------------//

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
joseluisysturiz
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: Any's xHarbour function support it?

Post by joseluisysturiz »

Buen dia, a eso se le llama PERMUTA...muy utilizado en los sistemas de loteria, habia hecho una hace bastante tiempo en la universidad como proyecto, pero ya ni recordaba como lo hice, gracias NAVARRO por tenerla publica, saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
richard-service
Posts: 807
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan
Has thanked: 1 time
Contact:

Re: Any's xHarbour function support it?( Solved )

Post by richard-service »

Hi
Now, it's work.
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
Post Reply