Post Reply 
Programming puzzles: processing lists!
04-20-2017, 05:30 PM (This post was last modified: 04-20-2017 05:40 PM by pier4r.)
Post: #6
RE: Programming puzzles: processing lists!
(04-20-2017 02:35 PM)Han Wrote:  Additional question: should the list be of the exact size as the input if no carry happens? This is important because the lazy approach would simply always return a list whose size is one larger than that of the input.

yes. I thought to put your observation in the main post, but there are already examples showing this.

Quote:EDIT: More comments:

#12 and #2 do not seem all that different

True, so I put a note on the #12.

Quote:#14 could easily run into overflow problems if your list is a minimum of 100 elements; did you mean to return the number as a list of digits in base 10?

No I did not thought about the overflow. You are right. I put a cap on the positive integers, this does not strike out the problem completely but it is less easy to run in overflow.


@ han: thanks for your solutions. I will surely use them when I will pick up the prime language, that so far I had no time. Having "small and ad hoc" programs sometimes is complementary to explain some syntax.

I still have to attack the problem with the 50g making use of STREAM, DOLIST, DOSUBS or functions for lists. I don't believe it will be difficult, but to make it fast, that is difficult.

If someone wants a random generator for lists, one can find one here:
Code:

  getRandomList
  \<<
    @0
    \->
    @input
    numElements
    minValue
    maxValue
    @local var
    @counter
    \<<
      \<<
        maxValue RAND * IP minValue +
      \>>
      'counter'
      1 numElements 1
      @ from 1 to numElements, increment of 1
      SEQ
    \>>
  \>>

It has to be adapted to generate lists with only two values that are not successive, though. (like 3 and 5)

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-20-2017 05:30 PM



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