Author Topic: Optimization failure led to me not understanding my own code  (Read 4666 times)

0 Members and 1 Guest are viewing this topic.

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Optimization failure led to me not understanding my own code
« 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?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Optimization failure led to me not understanding my own code
« Reply #1 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
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Optimization failure led to me not understanding my own code
« Reply #2 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!
« Last Edit: October 29, 2012, 06:04:46 pm by dinosteven »

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Optimization failure led to me not understanding my own code
« Reply #3 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
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Optimization failure led to me not understanding my own code
« Reply #4 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.
« Last Edit: October 29, 2012, 05:03:40 am by Runer112 »

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Optimization failure led to me not understanding my own code
« Reply #5 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
I'm not a nerd but I pretend:

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Optimization failure led to me not understanding my own code
« Reply #6 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

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Optimization failure led to me not understanding my own code
« Reply #7 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!
« Last Edit: October 29, 2012, 08:57:07 pm by dinosteven »