Post Reply 
[VA] My 2024's very first little teaser
01-17-2024, 02:14 AM (This post was last modified: 01-17-2024 05:30 AM by Valentin Albillo.)
Post: #1
[VA] My 2024's very first little teaser
 
Hi, all,

You may still remember my last teaser of 2023, the one which started the recent flurry of matrix-permanent-related posts. Now, it's only proper that my very first little teaser of 2024 should continue the trend, so let's get cracking ...
    You all know the matrix Determinant, aka det. Now, the matrix Permanent, aka per, is defined likewise but with all signs positive, no negative terms, i.e. like this:

            [Image: Permanent%2015b.jpg]

    and the teaser is that you should write an HP-71B program to compute the permanent of a given real 3x3 matrix like the one depicted above, subject to these three requirements:

    1. You must use an HP-71B(*) (physical/virtual,) other calcs or software simply won't do. If you're itching to post such non-HP71B code or symbolic math ramblings galore, please create another thread, don't post it to this one.
       
        (*) If desired, you may use the standard HP-71B enhancements, i.e. the Math, JPC or HP-IL ROMs.
       
    2. No arithmetic operators/operations should appear in your code, either explicitly (e.g. C=A*B) or "obfuscatedly" (e.g. C=VAL("A"&CHR$(42)&"B"). That includes +, -, *, /, ^, unary minus (e.g. C=-A), x2, DIV, MOD, ..., you get the idea.
       
    3. Also, no alpha strings/chars/operations at all.

If I see interest I'll post in a few days two different solutions: a 4-liner (158 bytes) and a 3-liner (135 bytes). Speed's mostly irrelevant but the shorter the code, the better. See what you can do ... Smile

Sample run:

      |  1  7  2 |
  M = | -3  4 -1 | , Per(M) = -36
      |  2  3  1 |


   >RUN
       ? 1,7,2,-3,4,-1,2,3,1 [END LINE]
-36

That's all. Your code/comments will be very welcome but please don't use CODE panels at all.

Best regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
01-17-2024, 11:02 AM
Post: #2
RE: [VA] My 2024's very first little teaser
Happy New Year Valentin!

Just for the avoidance of doubt, functions like DET, DOT, RECT, ABS, etc are allowed?

Cheers,

PeterP
Find all posts by this user
Quote this message in a reply
01-17-2024, 09:44 PM (This post was last modified: 01-17-2024 09:45 PM by PeterP.)
Post: #3
RE: [VA] My 2024's very first little teaser
Ok, assuming that i got the rules correct (which is a big assumption and if I have not I do apply for forgiveness), here is my attempt.
It is not pushing things into as few lines as possible as I was taught as a young kid at CERN that my code has to be readable easily if I want to survive there.... I think if one wanted to, the code could be squished into 4 lines, but it wont be pretty and I certainly would have a hard time understanding it)

10 Option Base 0 @ Dim A(2,2), B(2,2), C(5), D(5), X1(1), D2(1)
20 Mat B = ZER @ Mat D = CON @ Mat D2 = CON @ Mat Input A
30 For y = 0 to 3 Step 3
40 For x = 0 to 2 @ X1(0) = x
50 For i = 0 to 2 @ X1(1) = i
60 B(i,i) = A(i, Mod (dot(XI,D2),3))
70 Next i
80 X1(1)=y @ C(dot(X1,D2)) = Det(B)
90 Next x //
100 Mat A = TRN(A) @ For i = 0 to 2 @ Varswap A(0,i),A(2,i) @ Next i
110 Next y
120 Disp Dot(C,D) @ End

This, upon run, and entering the variables from the matrix, delivers the expected result -36

(The code uses the dot product extensively to add two numbers and det to calculate a product).

Cheers, Peter.

Cheers,

PeterP
Find all posts by this user
Quote this message in a reply
01-18-2024, 11:00 AM (This post was last modified: 01-18-2024 12:56 PM by J-F Garnier.)
Post: #4
RE: [VA] My 2024's very first little teaser
I too understand that explicit (or obfuscated) use of the 4 arithmetic operators is forbidden as well as their immediate derivates.
But high level commands that use indirectly or implicitly these operations must be allowed. Otherwise I don't see how to do anything useful.
[BTW, Peter, you used MOD which is not allowed, but you can easily use BINAND instead.]

And I too thought about the DOT command (of the Math ROM), because it does exactly what we need here: a sum of products.

Here is my simplest attempt:

10 OPTION BASE 1
20 DIM U(3),V(3),W(6),Y(2),Z(2)
30 MAT INPUT V,W
40 Y(1)=W(6) @ Y(2)=W(3) @ Z(1)=W(2) @ Z(2)=W(5) @ U(1)=DOT(Y,Z)
50 Z(1)=W(1) @ Z(2)=W(4) @ U(2)=DOT(Y,Z)
60 Y(1)=W(5) @ Y(2)=W(2) @ U(3)=DOT(Y,Z)
70 DISP DOT(U,V)

>RUN
V(1)? 1,7,2,-3,4,-1,2,3,1
-36


There is probably still room for code size optimisation (174 bytes for this deliberately non-packed version).

Edit:
Although the teaser is targetting the HP-71B only, the same program just runs fine on the 75C (with its Math ROM), but uses 321 bytes !

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
01-18-2024, 06:03 PM
Post: #5
RE: [VA] My 2024's very first little teaser
Thank you J-F for pointing out my mistake as well as the remedy!

I have also tried a different approach, doing the heavy lifting with a Det(A) with a couple signs shifted and then a correction for the one term.

10 Option Base 1 @ Dim A(3,3),B(3,3),C(3),D(3) @ Mat C=ZER @ Mat D=ZER @ Mat B=ZER @ Mat Input A
20 C(1)=LGT(.1) @ D(1)=A(2,3) @ A(2,3)=DOT(C,D) @ D(1)=A(1,2) @ A(1,2)=DOT(D,C)
30 C(1)=DET(A) @ B(1,1)=A(1,3) @ B(2,2)=A(2,2) @ B(3,3)=A(3,1) @ C(2)=DET(B) @ C(3)=C(2)
40 MAT D=CON @ DISP DOT(C,D)

I was not sure if the constant -1 was allowed or not so I avoided it for caution.

Cheers,

PeterP
Find all posts by this user
Quote this message in a reply
01-19-2024, 08:34 AM (This post was last modified: 01-19-2024 09:01 AM by J-F Garnier.)
Post: #6
RE: [VA] My 2024's very first little teaser
I have a solution in 3 BASIC lines and less than 130 bytes Smile
Not necessarily more efficient, but more compact in line with Valentin's hint ("Speed's mostly irrelevant but the shorter the code, the better").

I will post it in a few days to let others have a chance to play too.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
01-20-2024, 01:29 PM
Post: #7
RE: [VA] My 2024's very first little teaser
Here is another version thanks to J-F's hint, though it still needs 4 lines and is almost 200 bytes and is inelegant as it is ugly. There must be an elegant and more compact way to generate the permutations....

10 Option Base 1 @ Dim A(9), B(3,3), C(6), D(6) @ Mat B=ZER @ Mat D=CON @ Mat Input A

20 C(1)=FNA(1,5,9) @ C(2)=FNA(1,6,8) @ C(3)=FNA(2,4,9) @ C(4)=FNA(2,6,7) @ C(5)=FNA(3,5,7)

30 C(6)=FNA(3,4,8)

40 Disp DOT(C,D) @ Def FNA(X,Y,Z) @ B(1,1)=A(X) @ B(2,2)=A(Y) @ B(3,3)=A(Z) @ FNA=DET(B) @ END DEF

Cheers,

PeterP
Find all posts by this user
Quote this message in a reply
01-22-2024, 03:56 PM
Post: #8
RE: [VA] My 2024's very first little teaser
Here is my solution in 3 BASIC lines and 127 bytes:

20 DESTROY ALL @ OPTION BASE 1 @ DIM U(3),V(3),W(3),M(3,3) @ MAT INPUT U,V,W
40 M(1,2)=W(3) @ M(1,3)=W(2) @ M(2,1)=W(3) @ M(2,3)=W(1) @ M(3,1)=W(2) @ M(3,2)=W(1)
50 MAT V=M*V @ DISP DOT(U,V)


You will notice that there is a '*' sign, but it denotes a matrix multiplication, not an arithmetic operation, so I believe that it is allowed here.

Using the notation

    | a b c |
A = | d e f |
    | g h i |


the code is computing

| 0 i h |   | d |   | ei+fh |
| i 0 g | * | e | = | di+fg |
| h g 0 |   | f |   | dh+eg |


then

| a |   | ei+fh |
| b | . | di+fg | = aei+afh+bdi+bfg+cdh+ceg = per(A)
| c |   | dh+eg |


J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
01-23-2024, 10:22 PM (This post was last modified: 01-23-2024 10:23 PM by Valentin Albillo.)
Post: #9
RE: [VA] My 2024's very first little teaser
.
Hi, J-F,

(01-22-2024 03:56 PM)J-F Garnier Wrote:  Here is my solution in 3 BASIC lines and 127 bytes:

20 DESTROY ALL @ OPTION BASE 1 @ DIM U(3),V(3),W(3),M(3,3) @ MAT INPUT U,V,W
40 M(1,2)=W(3) @ M(1,3)=W(2) @ M(2,1)=W(3) @ M(2,3)=W(1) @ M(3,1)=W(2) @ M(3,2)=W(1)
50 MAT V=M*V @ DISP DOT(U,V)


You will notice that there is a '*' sign, but it denotes a matrix multiplication, not an arithmetic operation, so I believe that it is allowed here.

Sorry but no, that appearance of * in MAT V=M*V isn't acceptable and renders your solution invalid. As I made it clear in the requiremens, no +, -, *, / operators are acceptable, and I made no distinction between scalar and matrix operators, matter of fact I didn't even mention scalars or matrices at all, so the requirement applies to both and the spirit of the rule is that those characters should not appear in the code listing at all, no exceptions.

The reason why the MAT prefix must appear when the variables operated upon are matrices has historical roots, as the first implementaations of BASIC already featured the MAT prefix. From Wikipedia:
    "The first version BASIC language was released on 1 May 1964. Initially, BASIC concentrated on supporting straightforward mathematical work, with matrix arithmetic support from its initial implementation [...]"

so that the interpreter would consider (LET) C=A*B to be an scalar expression while MAT C=A*B would be treated as a matrix expression. Today, the MAT prefix might be substituted by operator overload, with (e.g.) * being used for scalar real/complex variables, real/complex matrix variables, etc., as is the case with the HP-15C, where the one-and-only [x] key can multiply scalars, matrices, scalar-matrix, complex values, etc.

This means that your MAT V=M*V is using the * operator exactly as V=M*V does, only adding the MAT prefix to indicate that the operator is operating on matrices instead of on scalar values, and so explictly including that operator in your code is disallowed (also, note that the HP-71B doesn't allow a matrix variable and a scalar variable to share the same name so the interpreter could have distinguished what flavor of the operator to apply based on the name and declaration of the variables involved with no need for a MAT prefix, but this would be non-standard BASIC syntax, certainly not ANSI-compliant.)

Finally, you say above: "there is a '*' sign, but it denotes a matrix multiplication, not an arithmetic operation", which I take it to mean that matrix multiplication is a different operation than scalar multiplication. But then, nothing in the requirements specifies that you can't use 1x1 matrices, so if I left that loophole in place then nothing prevents you from declaring your variables as 1x1 matrices, having just the one, single element, and then matrix multiplication reduces to purely scalar multiplication, isn't it ?

This trick, using 1x1 matrices and using MAT C=A*B (and MAT C=A+B) renders the whole matter utterly trivial and uninteresting. And you know from experience that my challenges, mini-challenges and teasers are all but trivial and unintertesting, so believe me if I tell you that there's much more here than meets the eye. Smile

I'll post my solutions (two of them) and comments next Thursday, 25th, so you have until then to amend your solution and even improve it if you feel like it.

Thanks for your continued interest and best regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
01-24-2024, 08:47 AM (This post was last modified: 01-24-2024 12:27 PM by J-F Garnier.)
Post: #10
RE: [VA] My 2024's very first little teaser
Hi Valentin,

(01-22-2024 03:56 PM)J-F Garnier Wrote:  You will notice that there is a '*' sign, but it denotes a matrix multiplication, not an arithmetic operation, so I believe that it is allowed here.

(01-23-2024 10:22 PM)Valentin Albillo Wrote:  Sorry but no, that appearance of * in MAT V=M*V isn't acceptable and renders your solution invalid.

As indicated by my remark above, I was aware of that my solution could be possibly rejected due to the rules but I really thought that matrix multiplication was acceptable in the same way as DOT (scalar or inner product) seems to be allowed.
I could argue more, but it's your challenge, your rules, and that's ok for me.

Still it was fun to play with your teaser and find this solution, and now eager to see yours :-)

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
01-26-2024, 07:32 AM (This post was last modified: 01-26-2024 07:33 AM by PeterP.)
Post: #11
RE: [VA] My 2024's very first little teaser
Slight improvement, now in 3 lines, but still very long (and in-elegant) at 191 bytes.

10 Option Base 1 @ Fix 4 @ Dim A(9), C(2), D(2) @ MAT D=ZER @ Mat Input A @ A(2)=FNM(A(2),-1)
20 A(6)=FNM(A(6),-1) @ H=FNM(A(3),FNM(A(5),A(7))) @ Dim A(3,3) @ Mat D=CON @ C(2)=DET(A)
30 C(1)=H @ D(1)=2 @ DISP DOT(C,D) @ DEF FNM(X,Y) @ C(1)=X @ D(1)=Y @ FNM=DOT(C,D) @ END DEF

Same principle still, matrix A has its elements (1,2) and (2,3) with a flipped signed, then the determinant of that matrix is calculated, which is now off only by 2* (1,3)*(2,2)*(3,1) which is added. The creation of the function FN M for the multiplication allowed to squeeze it into 3 lines.

Cheers,

PeterP
Find all posts by this user
Quote this message in a reply
01-26-2024, 04:00 PM (This post was last modified: 01-26-2024 05:29 PM by J-F Garnier.)
Post: #12
RE: [VA] My 2024's very first little teaser
Since Valentin didn't post his solution yet, I want to share an idea I got a few days ago that unfortunately lead me to nowhere.

The idea comes from the fact that det(A) and per(A) differs only by the sign of half of the terms.
If only the positive terms of det(A) exist (that is, the negative terms are zero), then we have per(A)=det(A).
It's trivial for a 2x2 matrix:
| a 0 |
| x d | , det(X)=per(X) = ad


For a 3x3 matrix, we can build:
| a 0 c |
| d e 0 | , det(X)=per(X) = aei + cdh
| 0 h i |

This is only a part of the target permanent and doesn't help directly, but the problem may be to build a matrix B with the 9 values a, b, ... i of our 3x3 matrix A, such as det(B)=per(A) and so the program would be reduced to just enter the elements and do DET().
Matrix B would have to be larger than 3x3 of course, maybe 5x5 or 6x6, with many elements=0 as in the trivial examples above.
Unfortunately, I didn't succeed to build such matrix by hand, and I can't think about a brute force approach to build it

Well, if somebody is more clever than me..

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
01-26-2024, 04:43 PM
Post: #13
RE: [VA] My 2024's very first little teaser
J-F, that was the idea I went down but I had not thought about making it a bigger matrix. If you flip the sign of the elements b and f ( to -b and -f) then det(A’) is perm(A) - ceg.

I like your idea of a 5x5 or 6x6!

My other thought which I was unable to get to anywhere with, was around recursion and if that is something that someone cleverer than me could use here

Cheers,

PeterP
Find all posts by this user
Quote this message in a reply
01-26-2024, 07:00 PM
Post: #14
RE: [VA] My 2024's very first little teaser
      
Hi, all,

In my OP I said 8 days ago: "If I see interest I'll post in a few days two different solutions". Regrettably, I've seen very little interest indeed but never mind, first I want to thank power forum's members PeterP and J-F Garnier for their interest in this teaser and for posting very nice working solutions, congratulations guys, much appreciated ! Smile

Now I think that a little disquisition is in order. I created this teaser several months ago and it was originally intended to be an April 1st Special mini-challenge, which typically are particularly weird or puzzling, usually seeming extremely difficult or even impossible to solve, see for example: As such, the original teaser's second requirement was simpler yet much more demanding than the one I specified for this "decaffeinated" version, which simply forbids using some operators (+, -, *, /, etc.,) and is way, way easier to solve, almost trivial when judging by the usual difficulty of my challenges. Not so with the original April 1st version, whose difficulty I greatly reduced in order to post it as an easy, affordable 2024's First Teaser, which I hoped would attract some considerable interest and likely a decent participation.

Well, no and no, actually it's got one of the lowest interest and participation rates in any of my challenges, next to none on both counts but as I said above, never mind, I'm posting here my two solutions: the elegant one for the (a) case below, and the shorter one for the (b) case below. Both solve the two variants of the teaser, the current easier one and the April 1st one, the latter replacing the second requirement (no +, -, *, /, etc.) by this one:
    2. Two choices; (a) You must use just one and only one math operation in all, or (b) just one and only one math operation and just one and only one variable.
which is obviously much more difficult to meet and might seem impossible to people who know how demanding evaluating permanents is. Even the naive definition requires 17 math operations (12 multiplications and 5 additions), and the best working solution by PeterP uses 6 executions of DET and 1 of DOT, plus 4 matrix variables, while the one by J-F uses 4 executions of DOT plus 5 variables. Thus, reducing that to just 1 math operation and 1 variable seems complicated, to say the least.

The sleuthing

If we're constrained to use just one math operation in all, it can't be a scalar operation but a matrix operation, and a cursory examination of the ones available quickly reveals that the only possible choice is the DET (determinant) operation and no other. The question is: can the Permanent evaluation be accomplished in terms of the Determinant ?

Well, for the 2x2 case it actually can, like this:

     Per( | a  b |   =  a*d-b*c = Det( | a -b |
          | c  d | )                   | c  d | )


so the question now becomes: for matrices M of dimension 3x3 and bigger, can we reassign the signs of their elements in such a way that the determinant of M' equals the permanent of M ?

Regrettably, it can be proved that this is not possible, no sign reassignment will make it work for arbitrary matrices 3x3 and bigger. But this is not the end, we can still wonder whether substituting each element of M by a linear combination of the elements could result in a matrix M' having det(M') equal Per(M). Alas, again this is provably impossible for arbitrary matrices M of dimensions 3x3 and bigger.

Is this the end ? No, we've been considering a matrix M' of the same dimension (say nxn) than the original matrix M, but if we consider a matrix M' of dimension m with m>n, then the elements of M can be assigned to M' in such a way that Det(M') = Per(M) and indeed there exist matrices and assignments with minimal dimensions at most m = 2^n-1, for instance:

[Image: Permanent%2001b.jpg]

Actually, that m > n and that m should grow exponentially with n (e.g. m = 2^n-1) is all but expected, since if m were polynomial in n then the cost of computing the permnaent would also be polynomial, which though unproved it's still extremely unlikely, as the best known deterministic algorithms require exponental running time and non-exponential ones would result in P=NP, which is believed (but not proven) to be impossible.

The implementation

Now that we have the 7x7 matrix above whose determinant is the permanent of any given 3x3 matrix, we can use the DET keyword as the only math operation, and the implementation is straightforward, just requiring an optimized way to assign the original 3x3 elements to the 7x7 auxiliar matrix.

My "elegant" solution, which solves both the current teaser (no +, -, *, /, etc.) and case (a) of the April's teaser is this 4-line, 158-byte piece of code:
    1  DESTROY ALL @ OPTION BASE 1 @ DIM M(7,7)
    2  DATA 0,A,D,G,0,0,0,0,1,0,0,I,F,0,0,0,1,0,0,C,I,0,0,0,1
    3  DATA C,0,F,E,0,0,0,1,0,0,H,0,0,0,0,1,0,B,0,0,0,0,0,1
    4  INPUT A,B,C,D,E,F,G,H,I @ READ M @ DISP DET(M)
Notice that other than the DATA statements, we only do four single-statement things: DIMension the 7x7 matrix, INPUT the 3x3 elements from the user, assign all nine elements at once to their proper locations in the 7x7 matrix with a single READ, and compute and output the sought-for permanent's value with a single DET.

It uses 9 scalar variables, while my "shorter" solution solves both the current teaser and case (b) above as it uses just one variable and is 3 lines, 131 bytes long (in my OP I said 135 bytes, but then realized that the customary DESTROY ALL isn't needed and removing it saves 4 bytes from the 135):
    1  OPTION BASE 1 @ DIM M(7,7) @ MAT M=IDN @ M(1,1)=0
    2  INPUT M(1,2),M(7,1),M(3,6),M(1,3),M(5,1),M(2,6),M(1,4),M(6,1),M(2,5)
    3  M(4,5)=M(3,6) @ M(3,7)=M(2,5) @ M(4,7)=M(2,6) @ DISP DET(M)
In this version, INPUT not only gets the 9 elements from the user but also automatically places them at their proper locations in the 7x7 matrix, then a few assignments place the remaining elements where they belong, while a previous MAT..IDN statement (this is not a math operation, just an assignment) took care of the 1's in the main diagonal and the 0's elsewhere.

Let's run any of them:

   >RUN
       ? 1,7,2,-3,4,-1,2,3,1 [END LINE]
-36

Regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
01-26-2024, 09:01 PM (This post was last modified: 01-26-2024 09:21 PM by PeterP.)
Post: #15
RE: [VA] My 2024's very first little teaser
Wonderful! Thank you for sharing. I especially liked the clever use of the read and input statements to fill the matrix.
Its seems J-F that you were thinking about the right approach while I had clearly failed to think “outside the 3x3 box” :-)

Thank you for sharing it Valentin, I enjoyed using my physical HP71 (I dont have a windows machine and Vbox does not seem to work under my sonoma setup to get the emu71 emulator working), especially as I am an obvious Noob when it comes to the 71.

Also thank you J-F for sharing your tips ans ideas, they certainly provided me with inspiration!

Cheers,

PeterP
Find all posts by this user
Quote this message in a reply
01-27-2024, 10:52 AM
Post: #16
RE: [VA] My 2024's very first little teaser
Great solutions, Valentin !

Your "elegant" solution is astonish, I'm not sure I would have thought about this efficient way to fill the 7x7 matrix. It is however specific to the 71B BASIC and will not work with other HP BASIC versions such as the HP-75C, and all in all I prefer your 2nd version, not only shorter but more standard.

Regarding the 7x7 matrix, I lately came to the idea that the solution was a single DET applied to a specifically built matrix, but there was no chance for me to build it by myself.
Knowing what to look for, it's now quite easy to find it in the literature, and indeed the way to create it is far above my math knowledge.

I learnt (again) something from your teaser, this time about the relation between permanents and determinants, and sorry if you got upset by my "invalid" solution (an optimization of my previous solution), for which you took the time to explain in details the reason for rejecting it - thanks for that.

As for the low participation, there are probably several reasons, but one may be that the game was restricted to the HP-71B, that is unfortunately not the most popular machine on this forum.


(01-26-2024 09:01 PM)PeterP Wrote:  Also thank you J-F for sharing your tips ans ideas, they certainly provided me with inspiration!

You're welcome !

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
01-27-2024, 05:07 PM (This post was last modified: 01-27-2024 05:08 PM by Maximilian Hohmann.)
Post: #17
RE: [VA] My 2024's very first little teaser
Hello,

(01-27-2024 10:52 AM)J-F Garnier Wrote:  As for the low participation, there are probably several reasons, but one may be that the game was restricted to the HP-71B, …

As far as I am concerned my lack of participation was not due do to a shortage HP-71Bs, as I own several of them and at least one MATH ROM. And there was no lack of interest either. But mainly a lack of basic (or maybe advanced?) knowledge in mathematics that would allow me to construct the 7x7 matrix M‘ from the input matrix.

However I learnt that HP-71B BASIC allows the use of variables in DATA statements which is an interesting feature that I completely overlooked so far!

Thanks for that.
Max
Find all posts by this user
Quote this message in a reply
01-30-2024, 08:54 PM
Post: #18
RE: [VA] My 2024's very first little teaser
  
Hi, PeterP, J-F Garnier, Maximilian Hohmann (and you lurkers,)

A few comments re your recent posts to this thread, in order:

PeterP Wrote:Wonderful! Thank you for sharing. I especially liked the clever use of the read and input statements to fill the matrix.

You're welcome, PeterP, and thanks for your appreciation. I always strive to show new techniques to help people better use their calcs so I'm glad you found the read/input tricks useful.


J-F Garnier Wrote:Great solutions, Valentin ! Your "elegant" solution is astonish, I'm not sure I would have thought about this efficient way to fill the 7x7 matrix. It is however specific to the 71B BASIC and will not work with other HP BASIC versions such as the HP-75C, and all in all I prefer your 2nd version, not only shorter but more standard.

Thank you very much, J-F. The reason I specified that people should use the HP-71B and no other models was because my "elegant" solution wouldn't run unchanged in any other model, including the ungainly clunker aka HP-75C.

Anyway, I prefer it vs. my "shorter" solution. By the way, I did try an optimization to the latter consisting in temporarily redimensioning the 7x7 matrix to a 49-element vector, so that the indexing would require just one index instead of two, like this:

   1  OPTION BASE 1 @ DIM M(7,7) @ MAT M=IDN @ DIM M(49)
   2  M(1)=0 @ INPUT M(2),M(43),M(20),M(3),M(29),M(13),M(4),M(36),M(12)
   3  M(26)=M(20) @ M(21)=M(12) @ M(28)=M(13) @ DIM M(7,7) @ DISP DET(M)


but no joy, it's actually 141 bytes long, i.e. 10 bytes longer than the non-redimensioned one. So much for the "optimization". Smile

By the way, I fully expected people to use DOT and DET for the easy teaser, but I'm mildly surprised that no one considered creatively using the HP-71B's Statistics functionality (STAT, ADD, DROP, TOTAL, etc.) though if I'm not wrong the clunker lacks those as well.

He Also Wrote:Regarding the 7x7 matrix, I lately came to the idea that the solution was a single DET applied to a specifically built matrix, [...] Knowing what to look for, it's now quite easy to find it in the literature [...]

Indeed, you just have to google it like this, and the very first link found points to the precise document where the 7x7 matrix I used can be found in page 9:
      [Image: Permanent%2019.jpg]

and a somewhat simpler explanation on how to construct the 7x7 matrix (and the 7x7 matrix itself) can be found here:
Permanent Determinant.
    Note: Symbolically computing the determinant of the 7x7 matrix should give the expression in my OP for the 3x3 symbolic determinant or an equivalent one. Try it !
And He Finally Wrote:As for the low participation, there are probably several reasons, but one may be that the game was restricted to the HP-71B, that is unfortunately not the most popular machine on this forum.

Well, so much for the forum, their loss. Sad


Maximilian Hohmann Wrote:However I learnt that HP-71B BASIC allows the use of variables in DATA statements which is an interesting feature that I completely overlooked so far! Thanks for that.

You're welcome, Maximilian, thanks for your interest and I'm glad you became aware of a new technique, that meets one of my goals here. By the way, DATA statements can hold not just numbers, strings and variables, but whole numeric or string expressions, which will be evaluated upon being accessed by READ statements, e.g.

   10 DATA 7.51E-23,"PARIS",35-LN(X)/LN(2),FNROOT(A,B,FVAR^5+FVAR-X)
   20 DATA X$[1,5]&Y$,FNA(X,Y)-FNB(Y,Z),DET(M)/DET(N)
    Note: In my "elegant" solution, the DATA statements would be 31 bytes shorter (and thus could coalesce into just one, making the solution a 3-liner) if a null item (e.g. 3,5,,7, ...,) could be read into a numeric variable or matrix element as a 0, which would've been trivial to implement at the time, but the HP-71B designers didn't see fit to allow for the possibility and attempting the feat just gives an error.

Regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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