Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: dinosteven on October 29, 2012, 12:44:08 am
-
A few months ago, I was making a program that made use of a mouse interface. I had thought that I had come up with some uber awesome optimization, but the code I came up with used more memory than if I had done it the standard way. *facepalm
I never changed it back, and now, months later, I can't understand it.
Basically, it checks the abs() of the distance the mouse is from the center of the button. Rather than a simple
If X<max and X>min and Y<max and Y>min
I came up with this:
If not(iPart((46-L₁(1))/19)) and not(iPart(43-L₁(2))/12
*sigh
Can someone please fix this mess?
-
If L₁(1)>27 and L₁(1)<65 and L₁(2)>31 and L₁(2)<55
...probably
-
Thanks.
But... Whoooh... After a quick optimization from
If not(stuffa) and not(stuffb
to
If not(stuffa or stuffb
In prgmA... My way is a 41 byte prgm; the classic way is 47 bytes...
It actually wasn't an optimization failure!
-
Might it be even better if you actually just use abs()?
If 19>abs(46-L₁(1)) and 12>abs(43-L₁(2
-
If prod({19,12}>abs(L1-{46,43
:P
EDIT: Or was the point not to produce optimized code? If so, nevermind me.
-
It acutally wasn't an optimization failure!
But... it acutally was a spelling failure D:
j/k nice :D
And runer always optimizes it more :o
-
Aww, I posted the same exact code as thepenguin77 over on TIBD D: But Runer, nice code o.o As long as L1 is 2 elements, that is a great optimisation :D
-
Unfortunately, it's 3 elements long; I'm using the DCS mouse lib.
EDIT: I just realized... This is being checked after a click, in which case, element 3 is 1 - meaning that prod() will work!