Post Reply 
Programming puzzles: processing lists!
04-21-2017, 09:03 PM (This post was last modified: 04-21-2017 09:05 PM by pier4r.)
Post: #19
RE: Programming puzzles: processing lists!
Some more results

more code: here
Code:

c2tester
    \<<
      10 @iterations
      10 @listSize
      { } @rndList
      { } @timeListC2vaV1
      { } @timeListDavidM
      { } @posCheckedListC2vaV1
      { } @posCheckedListDavidM
      \->
      iterations
      listSize
      rndList
      timeListC2vaV1
      timeListDavidM
      posCheckedListC2vaV1
      posCheckedListDavidM
      \<<
        1 iterations
        START
          listSize {3 5} getRandomListFromValues 'rndList' STO
          
          rndList 'c2vaV1' TEVAL
          @collect the timing
          OBJ\-> DROP
          'timeListC2vaV1' SWAP STO+
          @ collect the pos checked.
          'posCheckedListC2vaV1' SWAP STO+
          
          rndList 'c2DavidM' TEVAL
          @collect the timing
          OBJ\-> DROP
          'timeListDavidM' SWAP STO+
          @ collect the pos checked.
          'posCheckedListDavidM' SWAP STO+
        NEXT
        
        timeListC2vaV1
        posCheckedListC2vaV1
        timeListDavidM
        posCheckedListDavidM
      \>>
    \>>
    
    c2vaV1
    @given alist of length 100 of 3s and 5s, return the same list
    @ with 4 instead of 3 and 7 instead of 5
    
    @it seems correct
    @ 10 lists of 10 elements: 0.22 secs
    @ 50 lists of 100 elements: 2.32 secs
    \<<
      { } @resultList
      \->
      @input
      inputList
      @local
      resList
      \<<
        inputList
        \<<
          \-> 
          value
          \<<
            @we place a 4 on the stack
            value 3 ==
            4 IFT
            
            @we place a 7 on the stack otherwise
            value 5 ==
            7 IFT
            
            @we add the result to the output list
            @ we need to swap the values though otherwise
            @ the solution gets reversed.
            'resList' SWAP STO+
          \>>
        \>>
        DOSUBS
        
        resList
      \>>
    \>>

Correctness, both mine and DavidM (no other person contributed so far) are apparently correct.

Speed:
- challenge 1
Pier
@ 128 lists of 5 elements, average check length, 0.17 seconds
@ 10 lists of 100 elements, 1.73 sec average.
David
@ 128 lists of 5 elements, average check length, 0.061 seconds
@ 10 lists of 100 elements, 0.58 sec average.

- challenge 2
Pier
@ 10 lists of 10 elements: 0.22 secs
@ 50 lists of 100 elements: 2.32 secs
David
@ 10 lists of 10 elements: 0.08 secs
@ 50 lists of 100 elements: 0.59 secs

Outclassed!
Let's see for the next challenges if I can step up the solution. Furthermore the solution of david are very quick. I wonder if working with the stack could be faster or just be barely faster.

PS: I will compare more RPL based results if those appears during those days. Otherwise someone else has to do it.

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 - 04-21-2017 09:03 PM



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