05-12-2018, 05:48 PM

Inspired by Ángel Martin's 41CL quiz, I am intrigued by the concept of the "anti-Identity" 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 anti-Identity 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 1-0 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 anti-Identity 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 third-party commands).

- To make it more interesting on the 48-series 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 (49G-49g+-50g-48gII).

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 1-0 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 anti-Identity 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 third-party commands).

- To make it more interesting on the 48-series 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 (49G-49g+-50g-48gII).