Post Reply 
How do I learn RPL and solve this problem with it?
09-24-2017, 03:21 PM
Post: #6
RE: How do I learn RPL and solve this problem with it?
So I am really interested by your problem, that for what I understood is not that "difficult" for a couple of terms but for many it starts to be a challenge.

As usual, a lot of data is challenging to process in limited time.

So far I got "insufficient memory" (my 50g has 'only' 160 KB free in port 0) . I need to improve the algorithm because the search is too naive at the moment.

Nevertheless, such problems are always a chance to learn the vast amount of possible commands that the 50g offers. So thanks for it! (and I wonder how many others I miss that were posted here)

quick explanations nonetheless.


First of all my workflow. I use a windows XP system to develop for calculators and embedded devices.

What do I do? I have the 50g connected via USB. In notepad++ (using the "normal text language") I write my program. For this I create a duplicate of a template file and I call it with some name, like:

mathDirMisc.txt

The content at the start is this

Code:

%%HP: T(0)A(D)F(.);
@ alternative found online %%HP: T(3)A(R)F(.);
@ You may edit the T(0)A(D)F(.) parts.
@ The earlier parts of the line are used by Debug4x.

@ in npp, just select language "normal" to get rid of the highlight.

(yes I picked the template from debug4x mostly)

Then I create a directory, because according to the topic I may have several programs. Even one program may be split in subprograms so a directory is a nice container for it.

Code:

%%HP: T(0)A(D)F(.);
@ alternative found online %%HP: T(3)A(R)F(.);
@ You may edit the T(0)A(D)F(.) parts.
@ The earlier parts of the line are used by Debug4x.

@ in npp, just select language "normal" to get rid of the highlight.

DIR
  @here the code will be inserted

END


Then I insert what I need, normally a program, so it gets like

Code:

%%HP: T(0)A(D)F(.);
@ in npp, just select language "normal" to get rid of the highlight.

DIR
  @here the code will be inserted
  directoryEntryName
  \<<
     "hi there"
     "notice that the name of this program is equal to 'directoryEntryName'"
     "this program, when executed, will put those three strings on the stack"
  \>>
END

Note the use of digraphs, that are the ASCII translation of some important symbols on the 50g. In particular you find details about them in the hp 50g AUR. See http://www.hpmuseum.org/forum/thread-9090.html

With conn4x you can drag and drop the txt file on the calculator and it will be a valid directory afterwards.

Then it comes the actual program that I was trying.

Code:

%%HP: T(0)A(D)F(.);
@ in npp, just select language "normal" to get rid of the highlight.

DIR
  resistorsFindCouple
  @2017-09-24-16-00
  @Problem: given a list of resistors, compute any combination of two of them
  @in series or parallel to find the one that is closer to the input value.
  @see also www.hpmuseum.org/forum/thread-9150.html
 
  @Todo: 
  @ - faster search of possible values.
  @ - to precompute the list of resistors
  @ - to extend to more than 2 resistors.
  
  @requires: 
  @ - LSORT (see hp_calc_torrent and hpcalc.org)
  @ - listExt from DavidM (see hpmuseum forum or hp_calc_torrent)
  \<<
    { 10 12 15 18 22 27 33 39 47 56 68 82 }  "baseResistors" DROP
    DUP "allResistors" DROP
    { 0.1 10 100 1000 10000 100000 1000000 } "resistorRanges" DROP
    
    \->
    @input
    
    @localVar
    baseResistors
    allResistors
    resistorRanges
    
    \<<
      @first we build the list of all possible resistors from the base one.
      
      @for every element in the range of resistors we expand the list of available
      @resistors
      1 resistorRanges SIZE
      FOR position
        'allResistors'
        baseResistors
        resistorRanges position GET
        *
        STO+
      NEXT
      
      @now we order the resistors, although it is not strictly needed for the result
      allResistors :2:LSORT EVAL 'allResistors' STO
      
      @here we have all the resistors needed.
      @now we need to compute all the possible compositions of those in serial or parallel.
      
      allResistors
      2
      \<<
        "" "stringTag" DROP
        
        \->
        @input
        inputList
        
        @var
        stringTag
        \<<
          @we build the tag
          inputList \->STR 'stringTag' STO
          
          @we compute the values
          
          @series
          inputList LSUM
          "S" stringTag +
          \->TAG
          
          @parallel
        \>>
      \>>
      DOCOMB
    \>>
  \>>
END

but the search space is too large. So for now I have to think about something smarter. If you have questions about the simbols I used, ask! Asking is great to trigger possible explanations.

Wikis are great, Contribute :)
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? - pier4r - 09-24-2017 03:21 PM



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