Post Reply 
Programming puzzles: processing lists!
05-03-2017, 08:58 PM (This post was last modified: 05-03-2017 08:59 PM by pier4r.)
Post: #64
RE: Programming puzzles: processing lists!
DavidM thanks for the sysRPL hint. Long ago I read a similar one by Andreas Müller (software49g) . I see the power of sysRPL but I also see that is closer to assembly at times, therefore I would rather move on hpgcc / newRPL without USB , especially knowing that some nice users contributed with libraries to wrap back and forth objects with hpgcc. Like this: http://www.hpcalc.org/details/7177
The reason would be speed and still more readability than sysRPL , that at least for new users looks a bit too cryptic. (once one is used to RPL, then it becomes more familiar, of course)

Moreover from previous post it seems to me that you yourself can handle hpgcc programs (while I have the todo open since long time), so you may relate what I mean.

Of course if you want to do all the challenges in sysRPL, I suppose they will be useful as n-th example (this time on lists) for sysrpl programming.

(Plus I did not expect the sysRPL to be "only" 3 times as fast as the userRPL)

Anyway, back to list processing. I added some more challenges to the first post and I attacked the challenge #21. I still have to check the timings on #6 from the userRPL of DavidM.

#21 simple
Code:

    @ remove duplicates from a list of positive integers
    @ without maintaining the relative position
    
    @it seems to work.
    \<<
      0 @lastEl
      0 @resultList
      \->
      @input
      inputList
      @local var
      lastEl
      resultList
      \<<
        
        inputList SORT
        1
        \<<
          IF
            DUP lastEl ==
              @ if the last element is equal to the current
            NSUB 1 >
              @we keep the head
            AND
          THEN
            @ drop it, we have it already
            DROP
          ELSE
            @we leave the element
            @but we also save it
            DUP 'lastEl' STO
          END
        \>>
        DOSUBS
      \>>
    \>>

#21
Code:

    @ remove duplicates from a list of positive integers
    @ maintaining the relative position using the first appearance of an element.
    
    @it seems to work.
    \<<
      0 @lastEl
      0 @newEl
      { } @resultList
      \->
      @input
      inputList
      @local var
      lastEl
      newEl
      resultList
      \<<
        
        inputList
        1
        \<<
          @I'm fighting since one hour with DOSUBS not liking the
          @output of this subprogram. It seems that if I don't leave something
          @ to put in the result list, DOSUBS complains
          @ (although it is not always necessary, I can run a program made of just
          @ drop and it works. I guess DOSUBS is not so clear to me)
          @ so I decide to use the resultList but actually the list made by
          @ DOSUBS will be the real result.
          'newEl' STO
          IF
            resultList newEl POS 0 ==
              @element not found in the result list
          THEN
            @we save it
            'resultList' newEl STO+
            @plus we drop it for DOSUBS otherwise we get complains
            newEl
          END
        \>>
        DOSUBS
      \>>
    \>>

more code as usual on assembla, as linked in previous posts.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming puzzles: processing lists! - pier4r - 05-03-2017 08:58 PM



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