Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: dinosteven on October 29, 2012, 12:44:08 am

Title: Optimization failure led to me not understanding my own code
Post 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:
Code: [Select]
If not(iPart((46-L₁(1))/19)) and not(iPart(43-L₁(2))/12*sigh
Can someone please fix this mess?
Title: Re: Optimization failure led to me not understanding my own code
Post by: calc84maniac on October 29, 2012, 12:48:54 am
If L₁(1)>27 and L₁(1)<65 and L₁(2)>31 and L₁(2)<55

...probably
Title: Re: Optimization failure led to me not understanding my own code
Post by: dinosteven on October 29, 2012, 02:33:48 am
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!
Title: Re: Optimization failure led to me not understanding my own code
Post by: calc84maniac on October 29, 2012, 03:06:36 am
Might it be even better if you actually just use abs()?

If 19>abs(46-L₁(1)) and 12>abs(43-L₁(2
Title: Re: Optimization failure led to me not understanding my own code
Post by: Runer112 on October 29, 2012, 05:00:49 am
If prod({19,12}>abs(L1-{46,43

:P


EDIT: Or was the point not to produce optimized code? If so, nevermind me.
Title: Re: Optimization failure led to me not understanding my own code
Post by: aeTIos on October 29, 2012, 05:05:04 am
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
Title: Re: Optimization failure led to me not understanding my own code
Post by: Xeda112358 on October 29, 2012, 07:22:32 am
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
Title: Re: Optimization failure led to me not understanding my own code
Post by: dinosteven on October 29, 2012, 08:10:21 am
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!