The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
(Recursive) nested loops and IFs?
12-17-2015, 07:17 AM (This post was last modified: 12-17-2015 07:24 AM by chromos.)
Post: #1
(Recursive) nested loops and IFs?
Hi,
I'm writting solver for incomplete coordinates for multi caches (is there any geocacher out there?) which solves (brute force) inequalities, but their quantity and number of variables (and their names) is obtained from user via INPUT.

For six inequalities and four variables I have this static code:
(L1...coords via user input, something like {"5","0","3","5","(A+1)","(B)","(B-A-4)","0","1","5","2","4","(C-14)","(D-8)","(C-D+3)"}
L2...List of variable names,
L3, L4...Lists of variable boundaries,
L5...List of expressions
L6...valid variable values
Digitsum... digit sum of whole coordinates)

PHP Code:
SUBRFROMTO()
BEGIN
FOR Loop1 FROM L3(1TO L4(1) DO
 PRINT(); 
 PRINT(
"



                        Completed: "
+(Loop1*100/(L4(1)-L3(1)))+" %");
 FOR 
Loop2 FROM L3(2TO L4(2) DO
  FOR 
Loop3 FROM L3(3TO L4(3) DO
   FOR 
Loop4 FROM L3(4TO L4(4) DO
    
TempList:={};
    FOR 
Loop FROM 1 TO SIZE(L2) DO
     
EXPR(L2(Loop)+":=Loop"+STRING(Loop));
     
TempList(0):=EXPR(L2(Loop));
    
END;
    
Temp:=0;
    IF 
DigitSum>0 THEN
     
FOR Loop FROM 1 TO SIZE(L5) DO
      
Temp:=Temp+EXPR(L5(Loop));
     
END;
    
END;
    IF (
NOT(DigitSum>0) OR Temp==DigitSum-SubDigitSumTHEN
     
IF (EXPR(L5(1))>=AND EXPR(L5(1))<=9THEN
      
IF (EXPR(L5(2))>=AND EXPR(L5(2))<=9THEN
       
IF (EXPR(L5(3))>=AND EXPR(L5(3))<=9THEN
        
IF (EXPR(L5(4))>=AND EXPR(L5(4))<=9THEN
         
IF (EXPR(L5(5))>=AND EXPR(L5(5))<=9THEN
          
IF (EXPR(L5(6))>=AND EXPR(L5(6))<=9THEN
           L8
(0):=""+EXPR(L1(1))+EXPR(L1(2))+"° "+EXPR(L1(3))+EXPR(L1(4))+"."+EXPR(L1(5))+EXPR(L1(6))+EXPR(L1(7));
           
L9(0):=""+EXPR(L1(8))+EXPR(L1(9))+EXPR(L1(10))+"° "+EXPR(L1(11))+EXPR(L1(12))+"."+EXPR(L1(13))+EXPR(L1(14))+EXPR(L1(15));
           
L6(0):=TempList;
           
Dist:=acos(sin(PublLat)*sin(FUNCDMTODEG(L8(SIZE(L8))))+cos(PublLat)*cos(FUNCDMTODEG(L8(SIZE(L8))))*cos(FUNCDMTODEG(L9(SIZE(L9)))-PublLon));
           
IFERR(acos((sin(FUNCDMTODEG(L8(SIZE(L8))))-sin(PublLat)*cos(Dist))/(sin(Dist)*cos(PublLat)))) THEN
            L0
(0):=ROUND(6371*π/180*Dist,-3)+" km  error°";
           ELSE
            
θ:=360-acos((sin(FUNCDMTODEG(L8(SIZE(L8))))-sin(PublLat)*cos(Dist))/(sin(Dist)*cos(PublLat)));
            
L0(0):=ROUND(6371*π/180*Dist,-3)+" km  "+ROUND(θ,0)+"°";
           
END;
          
END;
         
END;
        
END;
       
END;
      
END;
     
END;
    
END;
   
END;
  
END;
 
END;
END;
END

I tried to build it recursively, but this is my first encounter with recursion so I can't find syntax which works.

I tried it with another approach where I packed everything as text and then I execute it via EXPR(...) and it works. Dissadvantage is unreadable code and everything must be in one string otherwise FOR and END will collapse.

Can anybody show me how build nested loops and IFs if I don't know their quantity beforehand?

Some screenshots:
                   

Prime G2, 15C CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(Recursive) nested loops and IFs? - chromos - 12-17-2015 07:17 AM



User(s) browsing this thread: 1 Guest(s)