RPL minichallenge: Create an antiIdentity Matrix

05122018, 05:48 PM
(This post was last modified: 05122018 09:50 PM by DavidM.)
Post: #1




RPL minichallenge: Create an antiIdentity Matrix
Inspired by Ángel Martin's 41CL quiz, I am intrigued by the concept of the "antiIdentity" matrix. Not having a 41CL prevents me from participating in the quiz, but I thought I might experiment with an RPL version of the first part his challenge: creating the antiIdentity matrix.
John Keith came up with a very similar RPL program to my first attempt, which essentially creates the matrix by generating a matrix of 1s and subtracting its identity from it. This makes for a compact solution, but it strikes me that it's not very internally efficient. The result is good, of course, but the majority of computation to create it is unnecessary (there's lots of 10 going on to get the final matrix). This extra computation slows it down. So here's the challenge: Given an integer input in stack level 1 representing the dimension of the square matrix, create the antiIdentity form as quickly as possible (all 1s except for 0s on the diagonal). Rules:  To simplify the approach, you may assume that the input is a valid integer > 1.  Standard User RPL commands only for HP 49G and later systems (no SysRPL, Saturn, SYSEVALs, or thirdparty commands).  To make it more interesting on the 48series systems, strategic SYSEVAL commands may be used if desired (provided they aren't used to simply execute an entire block of SysRPL or Saturn code).  Winners will be based on execution time of an input of 30, but the program should work properly with other inputs as well.  Execution time is defined as the time to complete the program on real hardware as opposed to an emulator.  Assume approximate mode for both constants and calculations on systems that support exact integers (49G49g+50g48gII). 

« Next Oldest  Next Newest »

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