So, I'm creating a program where I want to store a value to a matrix at (X,Y). However, the calculator comes up with an error with some values of X and Y for no apparent reason. For instance: 1→[A](1,1) works just fine, but when I try 1→[A](X,Y), while X and Y are both 1, I get a dimension error. This only happens while in the program, never at the home screen.
Can you post a snipper of code where the problem is? Storing 1 to [A](Y,X) shouldn't cause problems. Unless X or Y somehow changed and was greater than 1, a INVALID DIM error would be thrown because the dimension of [A] is 1x1, so the only reason that you are getting that error is X or Y is greater than 1.
𝔹𝕚𝕠_ℍ𝕒𝕫𝕒𝕣𝕕𝟙𝟚𝟠𝟚
:0identity(3→[A]
:Repeat A>7
:.1getKey→A
:End
:If A>7:8→B
:If A>8:6→B
:If A>9:4→B
:iPart(A)-C+10fPart(A→A
:If int(A/3):A-1→A
:int(A/3)+1→X
:3fPart(A/3→Y
:1→[A](X,Y
Sorry, I'm not sure how to post it in a separate box
Use the [code] block to insert code.
"Code will look like this→Str1
Disp Str1
I see what your problem is, make sure X and Y is 1, and not 0 or some other number.
𝔹𝕚𝕠_ℍ𝕒𝕫𝕒𝕣𝕕𝟙𝟚𝟠𝟚
So what I gather from your code, is this:
Set up a 3x3 Matrix
Wait until user presses a keycode above 70
If keycode is in the interval (70,80], B is 8
If keycode is in the interval (80,90], B is 6
If keycode is in the interval (90,105], B is 4
You take the iPart of the keycode, which will be in the set {7,8,9, 10}, subtract C, and add 10fPart of the keycode which will be in the set {1,2,3,4,5}
-- continued in next box --
This is where it gets tricky. What we know now is that A will be one of the numbers in the set {8,9,10,11,12,13,14,15}, minus C. It is important to note that certain keys such as 72 and 81 will result in the same A although they have different B's. It would be helpful to know what C is, since I don't see it being set anywhere in the code.
-- continued from above --
"If int(A/3)" will always be true, as long as A is not 0 or 2 so A equals A-1.
At this point, A is one of {7,8,9,10,11,12,13,14} minus C
If you take int(A/3)+1, and store it to X, it has to be in the set {1,2,3}, so int(A/3) has to be in the set {0,1,2}. Which means A has to be between 0 and 8. Because of this, C has to be either 6 or 7
3fpart(A/3) also has to be in the set {1,2,3}. This means that A cannot be divisible by 3, since it will result in 0 if it is. 3fpart(A/3) can result in {0,1,2}, so you really should be using 1+3fpart(A/3)
I probably didn't explain all that the best I could have, but basically the lines where you set X and Y are dependent upon what A and C are. You should change $3fpart(A/3$ into $1+3fpart(A/3$ because if A is divisible by three it will result in 0. If C is anything other than 6 or 7, your code won't work either. I think you may need to double check your if statements or make sure you're using int( in the right way. If you need more help, posting the full code as well as the purpose of the code would be the easiest way
Thanks. That was all very helpful. I've modified my code based on what you said, and it works fine now. The basic purpose of it is to store 1 to [A](3x3) based on which number key you pressed (1 through 9), so the 3x3 grid of numbers corresponds with the 3x3 matrix. There's probably a better way, but this is what I've come up with.
:0identity(3→[A]
:0→A
:Repeat A>7:.1getKet→A
:End
:If A>7:7→B
:If A>8:5→B
:If A>9:3→B
:iPart(A)-B+10fPart(A→C
:round(C/3,0→X
:-1+10fPart(A→Y
:1→[A](X,Y
If you use the patterns in the numbers, you can get it down to this:
0identity(3→[A]
DelVar K
Repeat (K>71)(K<95)not(sum(K={75,81,85,91
getKey→K
End
1→[A](iPart(.1K)-6,K-1-10iPart(.1K))
Let me know if you would like any explanation on how it works
Or to save a little more memory…
0identity(3→[A]
DelVar K
Repeat (Ans>71)(Ans<95)not(sum(Ans={75,81,85,91
getKey
End:Ans→K
1→[A](iPart(.1Ans)-6,K-1-10iPart(.1Ans
𝔹𝕚𝕠_ℍ𝕒𝕫𝕒𝕣𝕕𝟙𝟚𝟠𝟚
Your version doesn't actually save any memory, both are 72 bytes. If you wanted to save 8 bytes by using Ans you would have to do this:
0identity(3→[A]
Repeat (Ans>71)(Ans<95)not(sum(Ans={75,81,85,91
getKey
End
1→[A](iPart(.1Ans)-6,Ans-1-10iPart(.1Ans