How do I learn RPL and solve this problem with it?
09-26-2017, 06:46 PM
Post: #34
 Didier Lachieze Senior Member Posts: 1,101 Joined: Dec 2013
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
 « Next Oldest | Next Newest »

 Messages In This Thread How do I learn RPL and solve this problem with it? - setq - 09-24-2017, 12:48 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-24-2017, 01:29 PM RE: How do I learn RPL and solve this problem with it? - HP67 - 09-24-2017, 01:44 PM RE: How do I learn RPL and solve this problem with it? - John Keith - 09-24-2017, 03:03 PM RE: How do I learn RPL and solve this problem with it? - setq - 09-24-2017, 03:18 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-24-2017, 03:21 PM RE: How do I learn RPL and solve this problem with it? - HP67 - 09-24-2017, 04:06 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-24-2017, 04:10 PM RE: How do I learn RPL and solve this problem with it? - HP67 - 09-24-2017, 04:14 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-24-2017, 04:17 PM RE: How do I learn RPL and solve this problem with it? - HP67 - 09-24-2017, 04:25 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-24-2017, 06:02 PM RE: How do I learn RPL and solve this problem with it? - Brad Barton - 09-24-2017, 06:35 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-25-2017, 05:48 AM RE: How do I learn RPL and solve this problem with it? - HP67 - 09-25-2017, 04:08 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-25-2017, 05:39 PM RE: How do I learn RPL and solve this problem with it? - mfleming - 09-25-2017, 06:36 PM RE: How do I learn RPL and solve this problem with it? - Claudio L. - 09-25-2017, 08:27 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-26-2017, 06:03 AM RE: How do I learn RPL and solve this problem with it? - Claudio L. - 09-26-2017, 02:50 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-26-2017, 02:55 PM RE: How do I learn RPL and solve this problem with it? - Claudio L. - 09-26-2017, 06:37 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-26-2017, 06:57 PM RE: How do I learn RPL and solve this problem with it? - Claudio L. - 09-26-2017, 08:22 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-25-2017, 07:10 PM RE: How do I learn RPL and solve this problem with it? - Claudio L. - 09-25-2017, 07:41 PM RE: How do I learn RPL and solve this problem with it? - David Hayden - 09-25-2017, 07:55 PM RE: How do I learn RPL and solve this problem with it? - emece67 - 09-25-2017, 08:04 PM RE: How do I learn RPL and solve this problem with it? - Gerson W. Barbosa - 09-26-2017, 04:37 PM RE: How do I learn RPL and solve this problem with it? - Dieter - 09-26-2017, 07:01 PM RE: How do I learn RPL and solve this problem with it? - Claudio L. - 09-26-2017, 08:25 PM RE: How do I learn RPL and solve this problem with it? - Dieter - 09-26-2017, 08:36 PM RE: How do I learn RPL and solve this problem with it? - David Hayden - 09-25-2017, 08:17 PM RE: How do I learn RPL and solve this problem with it? - brickviking - 09-26-2017, 01:02 AM RE: How do I learn RPL and solve this problem with it? - John Keith - 09-26-2017, 12:06 PM RE: How do I learn RPL and solve this problem with it? - Claudio L. - 09-26-2017, 02:29 PM RE: How do I learn RPL and solve this problem with it? - David Hayden - 09-26-2017, 01:02 PM RE: How do I learn RPL and solve this problem with it? - Dieter - 09-26-2017, 06:20 PM RE: How do I learn RPL and solve this problem with it? - Didier Lachieze - 09-26-2017 06:46 PM RE: How do I learn RPL and solve this problem with it? - pier4r - 09-26-2017, 10:20 PM

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