Post Reply 
How do I learn RPL and solve this problem with it?
09-26-2017, 06:46 PM
Post: #34
RE: How do I learn RPL and solve this problem with it?
Here's a program for the HP Prime using some ideas from Claudio to speed it up (for me PPL is much easier than RPL for writing quick programs such as this one) :

Code:
Suffix(n)
BEGIN
 CASE
  IF 3≤LOG(n)<6 THEN n:=STRING(n/1ᴇ3)+"K" END;
  IF 6≤LOG(n)<9 THEN n:=STRING(n/1ᴇ6)+"M" END;
  DEFAULT n
 END;
END;


EXPORT RES(R)
BEGIN
LOCAL val:={10,12,15,18,22,27,33,39,47,56,68,82};
LOCAL rng:={.1,1,1ᴇ1,1ᴇ2,1ᴇ3,1ᴇ4,1ᴇ5,1ᴇ6};
LOCAL res:={};
LOCAL a,b,j,k,r0,r1,r2,rp;

FOR j FROM 1 TO 8 DO
 res:=CONCAT(res,val*rng(j));
END;

FOR j FROM 1 TO SIZE(res) DO
  a:=res(j);
  IF a>2*R THEN BREAK; END;
  IF a≥R THEN
    FOR k FROM j TO SIZE(res) DO
      b:=res(k);
      rp:=a*b/(a+b);
      IF ABS(R-rp)<ABS(R-r0) THEN
        r0:=rp;r1:=a;r2:=b;
      END; 
    END;
  END;
END;

r0:=ROUND(r0,−5);
rp:=ROUND(%CHANGE(R,r0),2);

PRINT(Suffix(r1)+" || "+Suffix(r2)+" = "+Suffix(r0)+" ("+rp+")");
RETURN {r1,r2,r0,rp};
END;

RES(523000) returns: 560K || 8.2M = 524.2K (0.23)
RES(117) returns: 120 || 4.7K = 117.01 (0.01)
RES(28) returns: 56 || 56 = 28 (0)

Note: the special character that may not be rendered correctly is the small E for EEX
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: How do I learn RPL and solve this problem with it? - Didier Lachieze - 09-26-2017 06:46 PM



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