Author Topic: Pythagorean Program  (Read 4438 times)

0 Members and 1 Guest are viewing this topic.

Offline Eniripsa96

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +3/-0
    • View Profile
Pythagorean Program
« on: February 02, 2010, 04:50:43 pm »
I have been working on a program, well it works but im making it better, that requests you to input the length of a leg of a triangle and it will give you all of the right triangles it can be in with all sides integers while it is still a leg. I don't have my cord right now but here's an example of what it would show/do.
Note: the etc at the end isnt in the end of the program, i just didnt want to type out all the outputs it gives
         the * means its an action
         the input 120 is just an example number you would type in, the following numbers all actual results it gives for 120 (go ahead, check them)

-Input ? 120-

*clears screen*

Possible Triplets (with the leg you entered being "A")

B=3599
C=3601
Area=215940

B=1798
C=1802
Area=107880

*pauses screen*
*clears screen*

B=1197
C=1203
Area=71820

B=896
C=904
Area=53760

*pauses screen*
*clears screen*

B=715
C=725
Area=42900

B=594
C=606
Area=35640

*pauses screen
*clears screen*
[etc]

EDIT: Alright, the program is uploaded, feedback is welcome and appreciated :P

EDIT: OOPS! I just noticed an extra character in the program that will make it error. If it tells you there's an error, delete the list symbol infront of the List1. (There will be 2 small Ls, delete the first one). Sorry about that, it was just a mistake from my optimizations.
« Last Edit: February 04, 2010, 04:35:50 pm by Eniripsa96 »

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Pythagorean Program
« Reply #1 on: February 02, 2010, 05:38:57 pm »
Wow, sounds nice.  I can't wait to see it. :)

Online DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Pythagorean Program
« Reply #2 on: February 03, 2010, 04:12:53 am »
Nice

It won't be much useful to me, though, since I finished school almost 7 years ago :P

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Pythagorean Program
« Reply #3 on: February 03, 2010, 10:28:57 am »
Interesting, I'm curious as to how this was done, cant wait to see the final program :)

Offline Eniripsa96

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +3/-0
    • View Profile
Re: Pythagorean Program
« Reply #4 on: February 03, 2010, 05:55:15 pm »
I think i have an idea where my cord is, so ill upload it soon.
Also, i worked on optimizing the code and reduced its size by about 15%. (I must be bad at making optimized codes without editing >_>)

EDIT: got another 2.5% less bytes taken up >_< went from nearly 1k to a little over 800
« Last Edit: February 03, 2010, 09:13:28 pm by Eniripsa96 »

Offline Eniripsa96

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +3/-0
    • View Profile
Re: Pythagorean Program
« Reply #5 on: February 04, 2010, 04:38:24 pm »
So, yeah, the download is up for anyone who wants it, just be sure to delete the L i accidently left in the code, it will point right to it if you hit GoTo after an error shows up. I apologize again for leaving that in there, I just didn't notice it when trying to optimize the code.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Pythagorean Program
« Reply #6 on: February 04, 2010, 04:46:24 pm »
Wow, that's really awesome!  I put in 96 and sat back, watching the program work.  It's a really neat, nice program.  Great job!

I noticed the last line leaves a zero on the screen.  Why don't you replace it with:
:Clrlist L1
:Output(1,1," //No spaces after the quote

Great job!  What math class are you taking? (What class would this help in?)
« Last Edit: February 04, 2010, 04:46:40 pm by ztrumpet »

Offline Eniripsa96

  • LV2 Member (Next: 40)
  • **
  • Posts: 28
  • Rating: +3/-0
    • View Profile
Re: Pythagorean Program
« Reply #7 on: February 04, 2010, 07:07:06 pm »
Im doing Trigonometry right now, but i developed the way (formula) to do it last year in Geometry
Also, thanks for the advice and thanks!
« Last Edit: February 04, 2010, 07:07:22 pm by Eniripsa96 »

Offline code241

  • LV2 Member (Next: 40)
  • **
  • Posts: 20
  • Rating: +0/-0
    • View Profile
Re: Pythagorean Program
« Reply #8 on: May 09, 2010, 11:49:07 am »
Thanks, you are going to help a lot of people.

Offline rthprog

  • LV2 Member (Next: 40)
  • **
  • Posts: 29
  • Rating: +5/-0
    • View Profile
Re: Pythagorean Program
« Reply #9 on: May 10, 2010, 08:28:49 am »
I'm not sure if you can use this, but the most efficient way (that at least I could think of) to find a third base given two bases (and the third value set to 0) is:
Code: [Select]
:Prompt A,B,C
:C²-B²-A²
:√(Ans-2Ansnot(C

I also made some minor optimizations to your code:

Code: [Select]
::"PYTHAGOREAN FINDER
:
:0→dim(L1
:100→dim(L1
:ClrHome
:Disp "ENTER LEG LENGTH"," ","DECIMALS ARE","ROUNDED
:Input A
:iPart(abs(A→A
:If A>10^4
:Then
:ClrHome
:Pause "THAT'S TOO LARGE
:prgmPYTHAGRN
:Return
:End
:1→C
:1→B
:If A=2iPart(A/2
:2→C
:ClrHome
:Output(1,1,"FINDING FACTORS
:Output(7,1,"AMOUNT FOUND
:Output(5,1,"CHECKING NUMBER
:While C≤A/2
:Output(6,3,C
:Output(7,14,B-1
:Output(8,1,200C/A
:Output(8,5,"PERCENT DONE
:If A=CiPart(A/C
:Then
:C→L1(B
:B+1→B
:Output(3,1,"FOUND FACTOR
:Output(4,3,C
:End
:C+2→C
:End
:ClrHome
:1→B
:1→J
:While J
:L1(B→J
:B+1→B
:End
:ClrHome
:B→L
:3-L1(1→K
:K+1→M
:Output(2,1,"FINDING EXTRA
:Output(3,1,"NUMBERS...
:While K<B-1
:If M≥B
:Then
:K+1→K
:K→M
:End
:If B=1
:Then
:ClrHome
:Pause "NO TRIPLETS!
:ClrHome
:Return
:End
:DelVar I
:If M<B
:∟L1(K)L1(M)→I
:If I>L1(B-1) and I<A
:Then
:Output(4,1,"FOUND EXTRA
:I→L1(L
:L+1→L
:End
:If I≥A
:Then
:K+1→K
:K→M
:End
:M+1→M
:End
:1→B
:2→D
:ClrHome
:Output(1,1,"POSSIBLE TRIPLET"
:L1(B)→C
:While C
:If D=10 or D=9
:Then
:Pause
:ClrHome
:1→D
:End
:Output(D,1,"B=
:Output(D,3,(A2-C2)/(2C
:Output(D+1,1,"C=
:Output(D+1,3,(A2+C2)/(2C
:Output(D+2,1,"AREA=
:Output(D+2,6,(A((A2-C2)/(2C)))/2
:D+4→D
:B+1→B
:L1(B→C
:End
:Pause
:ClrHome