I know there was a way to do this really fast... I just forgot how, unfortunately... Help me out?

EDIT: Figured it out.


Code:
:If sum(L1=L2)=dim(L1
:<code>
Where does a list fit in that If statement?

Would it be
Code:
If L1=L1=dim(L1
That would return an error because that code will return a list.
Wouldn't your (and my) code always return false? Since {1,2,3}={1,2,3} would return 1 for true and dim({1,2,3}) return three and 1=3 is false.

I know I've been out of the game for some years, but I still understand quite a bit. This has me stumped, though.
My code sums the results. Therefore, 3=3, making the expression true.
Well, you'd need to test equality and size. I believe If L1=L2 is sufficient, no??
True. But, I don't wanna use memory I don't have to.
Raylin wrote:
My code sums the results. Therefore, 3=3, making the expression true.
No... Because sum({1,2,3}={1,2,3)} would be 6=6 which would return 1 for true, and dim {1,2,3} is 3, and 1=3 is 0 for false.

I must be forgetting a larger, or simpler aspect of TI-BASIC since I left.
Raylin wrote:
True. But, I don't wanna use memory I don't have to.
Then I really don't understand what you're trying to do. If you don't have a previous copy of the list that you're checking, how will you possibly have a reference to see if it has changed?
KermMartian wrote:
Raylin wrote:
True. But, I don't wanna use memory I don't have to.
Then I really don't understand what you're trying to do. If you don't have a previous copy of the list that you're checking, how will you possibly have a reference to see if it has changed?
I was thinking that same thing but got off on a tangent trying to comprehend the code.

Question
KermMartian wrote:
Well, you'd need to test equality and size. I believe If L1=L2 is sufficient, no??

Unfortunately you'll get a dimension mismatch error if the lists are different sizes. You would need to so something like:
dim(L1
If Ans=dim(L2
Then
If sum(L1=L2)=Ans
Then
...
End
End

I know I've seen a better way to do this though.
Super Speler wrote:
KermMartian wrote:
Well, you'd need to test equality and size. I believe If L1=L2 is sufficient, no??

Unfortunately you'll get a dimension mismatch error if the lists are different sizes. You would need to so something like:

If dim(L1)=dim(L2
Then
If L1=L2
Then
...
End
End

I know I've seen a better way to do this though.
Oh, excellent point. What about If dim(L1)=dim(L2) and L1=L2? I forget what I saw about short-circuiting when looking at the TI-OS disassembly; I'm pretty sure it does not short-circuit.
KermMartian wrote:
Super Speler wrote:
KermMartian wrote:
Well, you'd need to test equality and size. I believe If L1=L2 is sufficient, no??

Unfortunately you'll get a dimension mismatch error if the lists are different sizes. You would need to so something like:

dim(L1
If Ans=dim(L2
Then
If sum(L1=L2)=Ans
Then
...
End
End

I know I've seen a better way to do this though.
Oh, excellent point. What about If dim(L1)=dim(L2) and L1=L2? I forget what I saw about short-circuiting when looking at the TI-OS disassembly; I'm pretty sure it does not short-circuit.

Unfortunately TI-Basic doesn't do that (as I just said on IRC and am putting here for other peoples sake).

I can't think of a use for this anyway. If you have access to the data in the original list why not just 'reset' it?
Super Speler wrote:

Code:
dim(L1
If Ans=dim(L2
Then
If sum(L1=L2)=Ans
Then
...
End
End


Why add an extra token?

EDIT: Oh wait, I see what you did there. But isn't it the same size both with and without using "Ans?"
You mean If Ans=sum(L1=L2? That's definitely what it should be. Smile
comicIDIOT wrote:
Super Speler wrote:

Code:
dim(L1
If Ans=dim(L2
Then
If sum(L1=L2)=Ans
Then
...
End
End


Why add an extra token?

EDIT: Oh wait, I see what you did there. But isn't it the same size both with and without using "Ans?"

Yes, it's the same size. This way, however, it doesn't have to evaluate the list twice. Evaluating Ans is far quicker then evaluating a large list.

Also, yeah, If Ans=sum(L1=L2 is the way to do that line (oops).
@comicIDIOT: {1,2,3}={1,2,3} returns {1,1,1}. The sum of {1,1,1} equals 3 which equals dim({1,2,3}).

@Speler: That's faster, right?
Raylin wrote:
@comicIDIOT: {1,2,3}={1,2,3} returns {1,1,1}. The sum of {1,1,1} equals 3 which equals dim({1,2,3}).

@Speler: That's faster, right?
Raylin, the problem is if one or both of the two lists may have changed size, the {1,2,3}={A,B,C} part might fail with a dimension error. You really should use a symbol like L1 to represent which part if the variable list; your notation is extremely confusing.
KermMartian wrote:
Raylin wrote:
@comicIDIOT: {1,2,3}={1,2,3} returns {1,1,1}. The sum of {1,1,1} equals 3 which equals dim({1,2,3}).

@Speler: That's faster, right?
Raylin, the problem is if one or both of the two lists may have changed size, the {1,2,3}={A,B,C} part might fail with a dimension error. You really should use a symbol like L1 to represent which part if the variable list; your notation is extremely confusing.


All right then. I'll change the notation. Also, the dimensions of the list will never change. In context, it will say if any of these variables have changed, then redisplay the information.
You need to have a backup list to compare with the current one. If min(L1=L2 will test every element, and if at least one of them doesn't check out, min( will show this by returning zero instead of one.

To report zero if the dimension has changed without worry of crashing, I recommend:

Code:
dim(L1)=dim(L2
If Ans
min(L1=L2

The Answer variable now holds either one or zero. Use this however you like.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement