(49G 49g+ 50g 48gII) NMDUP +- HP Forums (http://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (49G 49g+ 50g 48gII) NMDUP (/thread-10749.html) |
(49G 49g+ 50g 48gII) NMDUP - DavidM - 05-16-2018 01:12 PM DUPN and NDUPN are very useful RPL commands that also happen to be very fast ways of replicating objects on the stack. DUPN makes a single copy of the number of objects specified: 1 2 3 3 DUPN => 1 2 3 1 2 3 ...and NDUPN makes a single object with the specified number of copies, followed by the number of copies: 7 8 9 3 NDUPN => 7 8 9 9 9 3. Another similar scenario that can be useful has no single command, though. Specifically, replicating a group of objects a set number of times. The following SysRPL program can be used to perform this function: Code: :: Compile the above and give it a suitable name (I use NMDUP). To use it, place two numbers on the stack which represent the following: 2: N (the number of elements in the stack to replicate/group size) 1: M (the number copies of the elements to make) Note that M represents the total quantity of duplicates, not the additional ones. So a quantity of 0 is the same as dropping N elements, a quantity of 1 does nothing, etc. Likewise, an N of 0 will have no affect on the rest of the stack, as there are no stack items identified for replication. Examples: 1 2 3 3 0 NMDUP => <nothing> 1 2 3 3 1 NMDUP => 1 2 3 1 2 3 3 2 NMDUP => 1 2 3 1 2 3 1 2 3 2 5 NMDUP => 1 2 3 2 3 2 3 2 3 2 3 1 2 3 0 5 NMDUP => 1 2 3 |