Post Reply 
hp 28s - creating nested lists
02-16-2015, 06:51 PM
Post: #2
RE: hp 28s - creating nested lists
(02-16-2015 04:33 PM)mbrethen Wrote:  I need a program that will initialize a nested list filled with a value. For example:

Stack:
0
{3 4}

Output: {{0 0 0 0} {0 0 0 0} {0 0 0 0}}

Stack:
1
{2 3 4}

Output: {{{1 1 1 1} {1 1 1 1} {1 1 1 1}} {{1 1 1 1} {1 1 1 1} {1 1 1 1}}}

Following my first solution using SysRPL code for the inner loop. Be careful, using non or negative numbers inside the dimension list will crash your calculator with MEMORY LOST!

For secure testing use a HP28S emulator instead. You are warned!

Code:

NLIST
<<
  WHILE DUP SIZE 0 >
  REPEAT LIST->
    IF DUP 0 >
    THEN 1 - SWAP ->
n
      << ->LIST SWAP n
      >> # C53Bh
SYSEVAL # 3ACB5h
SYSEVAL # 3EFFh
SYSEVAL SWAP
    END
  END DROP
>>

The SYSEVAL sequence is standing for COERCE NDUPN {}N.

This is a quick shot variant in pure UserRPL (for list elements > 0):

Code:

NLIST
<<
  WHILE DUP SIZE 0 >
  REPEAT LIST->
    IF DUP 0 >
    THEN 1 - SWAP ->
n
      << ->LIST SWAP n
        WHILE 1 -
DUP 0 >
        REPEAT OVER
SWAP
        END DROP n
->LIST
      >> SWAP
    END
  END DROP
>>

Christoph
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
hp 28s - creating nested lists - mbrethen - 02-16-2015, 04:33 PM
RE: hp 28s - creating nested lists - Christoph Giesselink - 02-16-2015 06:51 PM



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