Post Reply 
newRPL: Alpha demo 0.9 released [UPDATED 2017-10-25]
10-27-2017, 12:59 AM
Post: #213
RE: newRPL: Alpha demo 0.9 released [UPDATED 2017-10-25]
(10-26-2017 09:05 PM)Gilles59 Wrote:  Hi,

Here is a program to find the numbers that are equal to the sum of the cubes of their digits

New RPL Version :
Code:
«
0 9 FOR 'a'
 0 9 FOR 'b'
  0 9 FOR 'c'
   IF 'a*100+b*10+c==a^3+b^3+c^3' THEN {a b c } EVAL END
  NEXT
 NEXT
NEXT
»
TEVAL : 1,06 sec

UserRPL version
Code:

«
0. 9. FOR a
 0. 9. FOR b
  0. 9. FOR c
   IF 'a*100.+b*10.+c==a^3.+b^3.+c^3.' THEN a b c 3. ->LIST END
  NEXT
 NEXT
NEXT
»
TEVAL : 289 sec (slow both in real or exact)

An other way en NewRPL :
Code:
<< 0 999 FOR 'n' n DUP ->STR UTF8-> #30h - 3 ^ ΣLIST == n IFT NEXT >>
TEVAL : 1,56"

UserRPL with GoferList lib (exact mode only):
Code:
 0 999 1 Seq « DUP ->STR Chars STR-> 3 ^ Sum ==  » Filter
TEVAL : who cares ? ;D
EDIT : Surprisingly, faster than previous UserRPL in 201 sec.

UserRPL with DavidM's ListExt library:

Code:
\<< 0. 999. FOR n
n DUP I\->NL 3. ^ LSUM SAME n IFT
            NEXT
\>>

TEVAL: 86.6 sec.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: newRPL: Alpha demo 0.9 released [UPDATED 2017-10-25] - John Keith - 10-27-2017 12:59 AM



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