Author Topic: Cool math hacks  (Read 28072 times)

0 Members and 2 Guests are viewing this topic.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Cool math hacks
« Reply #45 on: June 11, 2012, 09:58:55 pm »
EDIT: I opened up my notes and followed through some of my work and what I have found so far:
If there is a non-trivial solution for A2-B2=c, then it is of the form (A+2d)2-(B-4e)2 where d and e are integers. This will let me speed up my code as I can forget about half or 3/4 of the potential values. I am still working on cutting that down even more :)


I don't think this is true. And I see two problems with it.

1. (A+2d), the new A can't be greater than the original A. The reason why is that you can't get the difference between A2 and B2 any smaller than c because if you pick the best case scenario where B is 1 smaller, you'll get a new c by definition.
     So I think it's supposed to be (A-2d)

2. (B-4e), I ran some tests, and some needed 2e

Here's what I did: (A,B)
First column is number, second column is the trivial solution, third is the special solution, 4th is difference from trivial

Code: [Select]
9 5,4  3,0 2,4
15 8,7  4,1 4,6
21 11,10 7,2 4,8
25 13,12 5,0 8,12
27 14,13 6,3 8,10
33 17,16 7,4 10,12

But, (A-2d)2 - (B-2e)2 still eliminates half the numbers.

Edit:
    The table looks so much better in preview than in the actual forum, idk why.
Edit2:
    e is always greater than d, so that's another half of the numbers
« Last Edit: June 11, 2012, 10:13:52 pm by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

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: Cool math hacks
« Reply #46 on: June 23, 2012, 02:48:15 pm »
Yes, I did note the mistakes I made there. I made a mistake on one of the pages testing cases of parity.

EDIT: Also, I finally found mention of this technique while searching something unrelated. It is Fermat Factorization :)