Wiki Home

VFP Recursion Doesnt Work


Namespace: WIN_COM_API
I make this recursion code in PHP (works) and in VFP (doesn't work) and I cannot locate where is failing.

Is possible to help me. I think that is a configuration problem or another detail in VFP.
ptharso@hotmail.com

Suggestion: Declare the scope of your variables, for example
LOCAL x,y,z

The default scope is PRIVATE -- visible and modifyable in invoked code -- and that isn't usually what you want in recursion scenarios. -- Steven Black
*************************************************************************************************************
Thanks by attention. I had solve the problem yesterday. See the final code below. ptharso@hotmail.com
The problem was decode a string of octal numbers in 2**n values.

************************************************************************************************************
PROCEDURE card
&& '1...5....0...4'
obj = '44244442212317'
MESSAGEBOX("Vou comecar",48,"jogo")
jogar(obj,1)

PROCEDURE jogar(c,i)
LOCAL m,n as Integer

x = OCCURS("4",c)
y = OCCURS("2",c)
z = OCCURS("1",c)
IF (x+y+z) == 14 THEN
SELECT vol
APPEND BLANK
REPLACE c1 WITH x, cx WITH y, c2 WITH z, jg WITH c, mc WITH 0 && MESSAGEBOX(c,48,"jogo")
RETURN
ENDIF

DO WHILE i<15 AND SUBSTR(c,i,1)!='3' AND SUBSTR(c,i,1)<'5'
i=i+1
ENDDO

IF i<15 THEN
m = VAL(SUBSTR(c,i,1))
FOR n=0 TO 2
IF BITAND(m,2**n)>0 THEN && MESSAGEBOX("i="+STR(i)+"m="+STR(m),48,c)
jogar( LEFT(c,i-1) + STR(2**n,1,0) + RIGHT(c,14-i), i+1 )
ENDIF
NEXT
ENDIF

********************************************************************************************************************




PROCEDURE card
&&    '1...5....0...4'
obj = '55244442212411'
MESSAGEBOX("Vou comecar",48,"jogo")
jogar(obj,1)

PROCEDURE jogar(c,i)

x = OCCURS("4",c)
y = OCCURS("2",c)
z = OCCURS("1",c)
IF (x+y+z) == 14 THEN
   MESSAGEBOX(c,48,"jogo")
   RETURN
ENDIF

m = VAL(SUBSTR(c,i,1))
FOR i=i TO 14
    IF  (m==3 OR m>4 ) THEN
	FOR n=0 TO 2
            IF BITAND(m,2**n)>0 THEN
		jogar( LEFT(c,i-1) + STR(2**n,1,0) + RIGHT(c,14-i), i+1 )
	    ENDIF
        NEXT
	EXIT
    ENDIF
NEXT

********************************** PHP code*******************
< ?php
function jogar($c,$i) {
    $x=substr_count($c,'4');
    $y=substr_count($c,'2');
    $z=substr_count($c,'1');
    if ( ($x+$y+$z)==14 ) {
        print "($x+$y+$z)->$j
"; return; } while( ($c[$i]==4 || $c[$i]==2 || $c[$i]==1) && $i<14 ) $i++; for( $m[$i]=$c[$i],$n=0,$i<14; $n<3; $n++ ){ if ( $m[$i]&(1<<$n) ) { $c[$i]=(1<<$n); jogar($c,$i+1); } } } // 1...5....0...4 $obj = '13142445212473'; print "

".$_GET['obj']."

"; jogar($_GET['obj'],0); ? >
( Topic last updated: 2010.05.21 09:06:34 AM )