Any's xHarbour function support it?

Any's xHarbour function support it?

Postby richard-service » Mon May 23, 2016 5:58 am

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
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: Any's xHarbour function support it?

Postby cnavarro » Mon May 23, 2016 9:50 am

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 view

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

// 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
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Any's xHarbour function support it?

Postby joseluisysturiz » Mon May 23, 2016 3:53 pm

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
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

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

Postby richard-service » Wed Jun 01, 2016 8:37 am

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
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 53 guests