FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Any's xHarbour function support it?
Posts: 866
Joined: Tue Oct 16, 2007 08:57 AM
Any's xHarbour function support it?
Posted: Mon May 23, 2016 05: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 (r2503251254) => Borland C++ v7.7 32bit

MySQL v8.0

Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Any's xHarbour function support it?
Posted: Mon May 23, 2016 09: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 (fw): Select all Collapse
//----------------------------------------------------------------------------//

// 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
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: Any's xHarbour function support it?
Posted: Mon May 23, 2016 03: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!
Posts: 866
Joined: Tue Oct 16, 2007 08:57 AM
Re: Any's xHarbour function support it?( Solved )
Posted: Wed Jun 01, 2016 08:37 AM

Hi
Now, it's work.

Best Regards,



Richard



Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 32bit

MySQL v8.0

Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit

Continue the discussion