RPN Mini-Challemge: Splice & Split register blocks
|
12-29-2019, 06:04 PM
(This post was last modified: 12-30-2019 11:51 AM by Werner.)
Post: #7
|
|||
|
|||
RE: RPN Mini-Challemge: Splice & Split register blocks
Well, I wasn't done ;-)
I can do it in ~N*LOG(N) steps when N is a power of 2. When it isn't, it will use up the return stack, as follows: (I took the liberty of calling it 'LACE', because it is slightly different from SPLICE: SPLICE will leave the first and last elements in place, while LACE interleaves 1 2 3 4 .. 2N as N+1 1 N+2 2 .. so SPLICE(N) is equivalent to LACE(2,N-1) ) (BTW is there any way to get these tabs aligned? It shows up nicely in Notepad) (Edited in the meantime, thanks Ian) Code: X Y Z T Of course, in Free42, the return stack length is not such a problem ;-) Algorithm for SPLICE(9) == LACE(2,8): LACE(2,8) == SWAP(6..9,10..13); LACE(2,4); LACE(10,4); [code] 1 1 2 10 2 6 3 11 3 7 4 12 4 8 5 13 -> 5 9 6 14 10 14 7 15 11 15 8 16 12 16 9 17 13 17 18 18[\code] for SPLICE(8) == LACE(2,7): LACE(2,7) == SWAP(5..8,9..12); LACE(2,3); LACE(10,3); [code] 1 1 2 9 2 5 3 10 3 6 4 11 4 7 5 12 -> 9 8 6 13 10 13 7 14 11 14 8 15 12 15 16 16[\code] or, in general: LACE(A,N) == SWAP(A+[N/2]..A+N-1,A+N..A+N+[N/2]) IF N EVEN THEN DO LACE(A,N/2); LACE(A+N,N/2); END; ELSE DO LACE(A,[N/2]); LACE(A+N+1,[N/2]); END; Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
RPN Mini-Challemge: Splice & Split register blocks - Ángel Martin - 12-20-2019, 02:52 PM
RE: RPN Mini-Challemge: Splice & Split register blocks - Werner - 12-20-2019, 04:41 PM
RE: RPN Mini-Challemge: Splice & Split register blocks - Ángel Martin - 12-22-2019, 05:55 AM
RE: RPN Mini-Challemge: Splice & Split register blocks - J-F Garnier - 12-21-2019, 09:14 AM
RE: RPN Mini-Challemge: Splice & Split register blocks - Werner - 12-21-2019, 10:02 AM
RE: RPN Mini-Challemge: Splice & Split register blocks - Paul Dale - 12-21-2019, 11:42 PM
RE: RPN Mini-Challemge: Splice & Split register blocks - Werner - 12-29-2019 06:04 PM
RE: RPN Mini-Challemge: Splice & Split register blocks - ijabbott - 12-29-2019, 06:20 PM
|
User(s) browsing this thread: 1 Guest(s)