Programming Challenge!
02-19-2017, 10:40 PM (This post was last modified: 02-19-2017 10:57 PM by toml_12953.)
Post: #2
 toml_12953 Senior Member Posts: 2,096 Joined: Dec 2013
RE: Programming Challenge! A Solution
Here's a solution to the problem that tries to keep as close to the original as possible. It uses the same variable names and techniques as the original. If you run the original in BASIC and the below HPPL program, you'll see that they give the same answers. I hope you had fun!

Tom L

Code:
FNA(X,Y,Z) BEGIN   RETURN X*SIN(Y*0.01745329)*Z-16*Z^2; END; EXPORT PROJECTILE() BEGIN   LOCAL X,K,F2,W4,K1,ANS,TMP,M1;   X:=MAKELIST(0,C,0,126);K:=MAKELIST(0,C,0,2);   PRINT();   //REPEAT     F2:=0;     INPUT({M,A},"MUZZLE VELOCITY AND ANGLE",{"FT/SEC: ","DEGREES: "});     X(1):=0;     FOR T:=0.2 TO 25 STEP 0.2 DO       L:=IP(5*T+0.001);       X(L):=FNA(M,A,T);       IF X(L)<0 THEN          BREAK;       END;       IF X(L)-X(L-1)<=0 AND F2=0 THEN         IF X(L-1)-X(L-2)<X(L)-X(L-1) THEN            K(1):=X(L-2);           W4:=T-0.4+J;         ELSE           K(1):=X(L-1);           W4:=T-0.2+J;         END;         F2:=1;         FOR J:=0.01 TO 0.2 STEP 0.01 DO           K(2):=FNA(M,A,W4);           IF K(1)-K(2)<=0 THEN              BREAK;           END;           K(1)=K(2);         END;         K1:=MAX(K(1),K(2));       END;     END;     W:=L-1;     FOR J:=0.01 TO 0.2 STEP 0.01 DO       K(2):=FNA(M,A,T-0.2+J);       IF K(2)<0 THEN          BREAK;       END;       END;     PRINT("MAXIMUM HEIGHT IS "+K1+" FEET");     Y:=M*COS(A*0.01745329)*(T-0.2+J-0.01);     PRINT("RANGE IS "+Y+" FEET");     PRINT("TOTAL TIME AIRBORNE IS "+(T+J-0.01)+" SECONDS");     IF K1+14>60 THEN        M1:=1/(IP(K1/60+1));       PRINT("SCALE OF HEIGHT IS 1 SPACE = "+1/M1+" FEET");     ELSE        M1:=1;     END;     TMP:=TAB(14);     FOR D:=1 TO 30 DO       TMP:=TMP+"+";     END;     PRINT(TMP);     PRINT("0"+TAB(14)+"+");     FOR N:=1 TO W DO         PRINT(STRING(0.2*N*M*COS(A*0.01745329),2,4)+" +"+TAB(X(N)*M1)+"*");     END;     //INPUT({{ANS,[2]}},"ANYMORE (YES OR NO)?");    //UNTIL UPPER(ANS) == "NO"; END;

Here's the TAB Function:
Code:
EXPORT TAB(X) BEGIN   LOCAL I,T;   T:="";   FOR I:=1 TO X DO     T:=T+" ";   END;   RETURN T; END;

Tom L
Cui bono?
 « Next Oldest | Next Newest »

 Messages In This Thread Programming Challenge! - toml_12953 - 02-19-2017, 10:35 PM RE: Programming Challenge! A Solution - toml_12953 - 02-19-2017 10:40 PM RE: Programming Challenge! - Han - 02-20-2017, 04:39 PM RE: Programming Challenge! - toml_12953 - 02-20-2017, 10:52 PM

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