Post Reply 
RPL mini-challenge: Create an anti-Identity Matrix
05-12-2018, 08:44 PM (This post was last modified: 05-12-2018 08:48 PM by 3298.)
Post: #5
RE: RPL mini-challenge: Create an anti-Identity Matrix
There is a weird little command called RDM that's probably not that useful in many contexts, but here it can do some work.
The idea is that a matrix like this:
Code:
[
  [ 0. 1. 1. 1. 1. ]
  [ 0. 1. 1. 1. 1. ]
  [ 0. 1. 1. 1. 1. ]
]
is almost identical to a 4-by-4 anti-identity matrix when read line by line (only the final 0. is missing). And RDM is all we need to reformat this into the desired anti-identity matrix (it creates new elements with value 0. as needed, so the missing element is not a problem; we don't even need to overwrite it afterwards because in this case we want exactly that value). In the end all we have to do is generate this other matrix which looks nicely uniform, so we can just do it with a pair of NDUPN and some \->ARRY and ROW\-> sprinkled in. The rest of the code should be trivial to follow:
Code:
\<<
  0. 1. PICK3 NDUPN 1. + \->ARRY
  OVER 1. - NDUPN ROW\->
  SWAP DUP 2. \->LIST RDM
\>>
Comparing the average timing over 20 runs with input 30. (1.02098_s) with that of the trivial solution using primarily IDN and CON (2.443935_s in my implementation), the RDM approach seems to be quite a bit faster. For reference, this is my implementation of the trivial solution:
Code:
\<<
  DUPDUP 2. \->LIST 1. CON
  SWAP IDN -
\>>
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: RPL mini-challenge: Create an anti-Identity Matrix - 3298 - 05-12-2018 08:44 PM



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