Hi
I have a 123 number
What's function that let me show these
123,132,213,231,312,321
richard-service wrote:Hi
I have a 123 number
What's function that let me show these
123,132,213,231,312,321
//----------------------------------------------------------------------------//
// 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
//----------------------------------------------------------------------------//
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 53 guests