Post Reply 
Programming puzzles: processing lists!
10-17-2017, 07:20 PM
Post: #207
RE: Programming puzzles: processing lists!
(10-17-2017 05:00 PM)pier4r Wrote:  Added the #39 , it is super easy to solve but I'd like to know if there are quick/elegant ways to solve it.

Not sure how elegant this is, but given the arguments in the order specified in your first post (list, position, offset):
   GET + PUT

...would seem to work.

(10-17-2017 05:00 PM)pier4r Wrote:  I thought that one could do

{ 1 2 3 4 5 } { 0 0 3 0 0 } ADD
but building the second list is not less verbose than the process written above. At least for my knowledge.

Does someone know a quick way to build a list with only one non zero value in a specified position?

That will work, of course, but you'd end up doing a lot of unnecessary additions for a large list. I haven't tested it, but I can't imagine that those additions would be faster than a simple GET/ADD/PUT combination.

If you still want to play around with that, though, the following can be used to generate a list of 0s with a single constant in a specified position.

Stack setup
3: constant
2: position
1: list size

   0 SWAP
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: Programming puzzles: processing lists! - DavidM - 10-17-2017 07:20 PM

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