HHC 2019 will be in Reno, Nevada, Sept 21-22
09-30-2019, 09:54 PM
Post: #61
 David Hayden Member Posts: 273 Joined: Dec 2013
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
Claudio, can you explain how this part of the code works? I'm guessing that RANGE produces a list of numbers from 0 to 9 by 1's. And I think NEWRPL's + operator adds corresponding elements in lists (rather than appending lists). But how does it create a list of 1000 numbers?

Thanks,
Dave

(09-30-2019 04:15 PM)Claudio L. Wrote:
Code:
 «   0 9 1 RANGE      @ Make a case-list of numbers 0-9  3 ^ DUPDUP + +    @ Sum of the cubes of the digits of ALL numbers from 0 to 999
10-01-2019, 02:11 AM
Post: #62
 Claudio L. Senior Member Posts: 1,634 Joined: Dec 2013
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
(09-30-2019 09:54 PM)David Hayden Wrote:  Claudio, can you explain how this part of the code works? I'm guessing that RANGE produces a list of numbers from 0 to 9 by 1's. And I think NEWRPL's + operator adds corresponding elements in lists (rather than appending lists). But how does it create a list of 1000 numbers?

Thanks,
Dave

(09-30-2019 04:15 PM)Claudio L. Wrote:
Code:
 «   0 9 1 RANGE      @ Make a case-list of numbers 0-9  3 ^ DUPDUP + +    @ Sum of the cubes of the digits of ALL numbers from 0 to 999

Yes, sorry, I posted in a rush with no time to explain.
RANGE is similar to the Python Range(), creates a list of integers, giving start, end and step. In newRPL, it creates not a list but a case-list. It's a new type of object, similar to a list but with different overloaded operators, so it behaves different.
I call them case-lists because it's a list of alternative results. When you assign a case list c{ 1 2 3 } to a variable X, it means X may take any of the values in the list. For example the square root of 4 could return c{ 2 -2}, because it could take either value.
When you add 2 case-lists, the result is all possible combinations: c{1 2 } c{ 3 4 } + returns c{ 1+3 2+3 1+4 2+4} since there could be 4 different results.
Back to the code above, RANGE just makes the case-list with 0 to 9. 3 ^ simply cubes each element. DUPDUP + + results in a list with all possible combinations of the sum of the cubes. The resulting list has all 1000 numbers, and the order of those numbers happens to match the order of the numbers 0 to 999. So the index of the list NSUB-1 is also the 3-digit number that gave origin to each element.
Case-lists were added to newRPL to be able to process expressions where a function may have multiple results, or when you want to try several values for a variable on a single EVAL.
So far it's used by ALLROOTS, which returns all roots where XROOT returns only the principal value, but case-lists are really handy.
10-03-2019, 08:24 PM
Post: #63
 David Hayden Member Posts: 273 Joined: Dec 2013
RE: HHC 2019 will be in Reno, Nevada, Sept 21-22
I ported my program to the 35s. Due to the lack of labels and dearth of indirect addressing registers, it was much harder than I thought. Now I understand why people view the 42s as the pinnacle of RPN models. It looks like the HP32s started the trend of few labels and single-letter variables. Is that right?

Anyway, here is the code. My apologies for the comments not lining up. It runs in 1 minute 22 seconds:
Code:
D001    LBL D             9            ; Precompute 03-93         STO I         RCL I D005    3         y^x         STO(I)         DSE I         GTO D004 D010    CLx         STO(I)         -26            ; Store results in Z..W         STO K         1.009 D015    STO L        ; X from 1-9         RCL L         STO I         RCL(I)         ; X^3         STO A        ; S1 D020    RCL I         IP         100         ×         STO D        ; N1 D025    .009         STO M         RCL M         STO I         RCL(I) D030    RCL+ A         STO B        ; S2         RCL I         IP         10 D035    ×         RCL+ D         STO E        ; N2         .009            ; For Z=0 to 9         STO J D040    RCL(J)         RCL+ B        ; S3         RCL J         IP         RCL+ E        ; N3 D045    X≠Y?             ; S≠N?          GTO D052        ; branch         RCL K        ; If S=N then store         STO I         R↓ D050    STO(I)         ISG K         9         +         x<y?             ; N+9 < S? D055    GTO D058            ; break out of z loop         ISJ J            ; Loop for X digit         GTO D040         ISG M        ; Loop for Y digit         GTO D027 D060    ISG L                ; Loop for X digit         GTO D014         RCL Z         RCL X         RCL Y D065    RCL W         RTN
 « Next Oldest | Next Newest »

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