Moderador: Moderadores
Function Main()
aCmb:=CombMil("9756") //chame a funcao passando o numero que sera combinado
*Vai retornar uma matriz com as combinacoes
For i_=1 to len(aCmb)
? aCmb[i_]
Next
Return Nil
Function CombMil(cMil)
Local cCmbPos:="1234|1243|1324|1342|1423|1432|2134|2143|2314|2341|2413|2431|3124|3142|3214|3241|3412|3421|4123|4132|4213|4231|4312|4321|"
Local aRet_:={}
For e_=1 to 4
cNum_:=SUBS(cMil,e_,1)
cCmbPos:=StrTran( cCmbPos, Str(e_,1), cNum_)
Next
For e_=1 to 24
cCob_:=Left(cCmbPos,4)
AADD(aRet_,cCob_)
If e_<24
cCmbPos:=SUBS(cCmbPos,6)
endif
Next
Return aRet_
//Function Main() // para Clipper deixe comentado...
Local GetList:={}
Local x, xy, cChar
Local cNumero, cNumeroFix
Local aMatriz:={}, nPosi:=0
Clear Screen
cNumero := Space( 4 )
@ 3,5 SAY "Digite um Numero:" GET cNumero PICTURE "9999"
Read
cNumero := AllTrim( cNumero )
If Empty( cNumero )
Return Nil
Else
cNumeroFix := cNumero
EndIf
While nPosi < Len( AllTrim( cNumero ) ) // trata a milhar principal...
nPosi++
For x = 1 To Len( AllTrim( cNumero ) )
cChar := SubSt( cNumero, x, 1 )
cChar := cChar + Stuff( cNumero, x, 1, "" )
If AScan( aMatriz, cChar ) = 0
AaDd( aMatriz, cChar )
EndIf
If x = Len( AllTrim( cNumero ) )// - 1
cNumero := cChar
EndIf
Next
EndDo
nPosi := 0
For xy:=1 To Len( aMatriz ) // trata as combinações...
cNumero := aMatriz[xy]
For x = 1 To Len( AllTrim( cNumero ) )
cChar := SubSt( cNumero, x, 1 )
cChar := cChar + Stuff( cNumero, x, 1, "" )
If AScan( aMatriz, cChar ) = 0
AaDd( aMatriz, cChar )
EndIf
Next
Next
Clear Screen
aMatriz := Asort( aMatriz )
? "Combinacoes de:", cNumeroFix
?
For x:=1 To Len( aMatriz )
? aMatriz[x]
Next
?
?
//Return Nil
aDigitos:={9,7,5,6}
for a=1 to 4
for b=1 to 4
for c=1 to 4
for d=1 to 4
if a<>b .and. a<>c .and. a<>d .and. b<>c .and. b<>d .and. c<>d
? str(aDigitos[a],1)+str(aDigitos[b],1)+str(aDigitos[c],1)+str(aDigitos[d],1)
endif
next
next
next
next
#include "inkey.ch"
PROCEDURE Main
LOCAL cNumero := "9756", aList := {}, nCont
SetMode( 30, 80 )
CLS
? Time()
Combina( cNumero, "", @aList )
ASort( aList )
FOR nCont = 1 TO Len( aList )
? nCont, aList[ nCont ]
NEXT
? Time() + " ESC"
DO WHILE Inkey(0) != K_ESC
ENDDO
RETURN
FUNCTION Combina( cNumeros, cAcumulado, aList )
LOCAL cNumero, nCont
IF Len( cAcumulado ) == Len( cNumeros )
AAdd( aList, cAcumulado )
RETURN NIL
ENDIF
FOR nCont = 1 TO Len( cNumeros )
cNumero := Substr( cNumeros, nCont, 1 )
IF ! cNumero $ cAcumulado
Combina( cNumeros, cAcumulado + cNumero, @aList )
ENDIF
NEXT
RETURN NIL
Usuários vendo este fórum: Nenhum usuário registrado online e 5 visitantes