Post Reply 
How do I learn RPL and solve this problem with it?
09-25-2017, 05:48 AM (This post was last modified: 09-25-2017 05:50 AM by pier4r.)
Post: #14
RE: How do I learn RPL and solve this problem with it?
My second approach, inspired by the discussion with hp67 (thanks!) is to pre-compute the value and then having the real program searching the right value among the pre-computed ones .

So at the moment I am in the process to pre compute the value (not storing them on the SD card at first) but on the 50g it takes quite a while.

Since I discovered that the 50g when it is busy does not update the clock, I can tell how long it is computing.

In this moment the actual date is: 2017-09-25-07-46
The calculator shows the clock locked at 2017-09-24-22-18

I checked the program once again and I do not see parts where it can end in loop, so I leave it running because it can end from a moment to another.

Surely I feel that there would be room for improvement.

Code:

\<<
    { 10 12 15 18 22 27 33 39 47 56 68 82 }  "baseResistors" DROP
    { 1. 1.2 1.5 1.8 2.2 2.7 3.3 3.9 4.7 5.6 6.8 8.2 
10. 12. 15. 18. 22. 27. 33. 39. 47. 56. 68. 82. 100. 120. 
150. 180. 220. 270. 330. 390. 470. 560. 680. 
820. 1000. 1200. 1500. 1800. 2200. 2700. 3300. 
3900. 4700. 5600. 6800. 8200. 10000. 12000. 
15000. 18000. 22000. 27000. 33000. 39000. 
47000. 56000. 68000. 82000. 100000. 120000. 
150000. 180000. 220000. 270000. 330000. 390000. 
470000. 560000. 680000. 820000. 1000000. 1200000. 
1500000. 1800000. 2200000. 2700000. 3300000. 
3900000. 4700000. 5600000. 6800000. 8200000. 
10000000. 12000000. 15000000. 18000000. 
22000000. 27000000. 33000000. 39000000. 47000000. 
56000000. 68000000. 82000000. } "allResistors" DROP
    DUP SIZE "allResistorsNumber" DROP
    { 0.1 10 100 1000 10000 100000 1000000 } "resistorRanges" DROP
    {} "resultSerial" DROP
    {} "resultParallel" DROP
    0 "value1" DROP
    0 "value2" DROP
    {} "allResistorsListTemp" DROP
    {} "allResistorsListTemp2" DROP
    
    \->
    @input
    
    @localVar
    baseResistors
    allResistors
    allResistorsNumber
    resistorRanges
    resultSerial
    resultParallel
    value1
    value2
    allResistorsListTemp
    allResistorsListTemp2
    
    \<<
      \<<
        @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      
        @we can also save the result as precomputed list
      \>> 
      DROP
        @not needed, we have the list precomputed now.
    
      @here we have all the resistors needed.
      @now we need to compute all the possible compositions of those in serial or parallel.
      
      @computing the result in order, so from the position of the element we can
      @infer the two components making the element (maybe not that easy with more than)
      @two components.
      @Cannot use docomb for this due to the not predictable way of making combinations.
      
      allResistors 'allResistorsListTemp' STO
      
      1 allResistorsNumber 1 -
      FOR index1
        allResistorsListTemp LPOP
        'value1' STO
        'allResistorsListTemp' STO
        
        allResistorsListTemp 'allResistorsListTemp2' STO
        
        index1 1 + allResistorsNumber
        START
          allResistorsListTemp2 LPOP
          'value2' STO
          'allResistorsListTemp2' STO
          
          'resultSerial'
          value1 value2 +
          STO+
        NEXT
      NEXT
      
      resultSerial
    \>>
  \>>

Once again, setq, if you have question about the syntax of the program (I have no doubts that you can figure out the meaning once being able to decode the syntax), ask!


edit: discovered that the code block on thi forum limits the shown text vertically but not horizontally. It was not expected.

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-25-2017 05:48 AM



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