NO

Author Topic: A simple console program for Pythagorean Primitives  (Read 3758 times)

defrancis7

  • Guest
A simple console program for Pythagorean Primitives
« on: October 21, 2015, 08:04:04 PM »
I thought I would share the source code for a console32 program to find Primitive Pythagorean Triplets.  This is an example of the type of programs I write, which is mostly for my own interest.  Be forewarned, I may not have used the best or latest programming techniques; but, these do work.  (I did a few test examples by hand and calculator to confirm that the program was working correctly.)

For those that do not know:  Pythagorean Triplets are completely integral, (whole number), solutions to the equation x^2 + y^2 = z^2.  A primitive triplet is the lowest unique solution.  For example:  {3,4,5} is the primitive triplet of {6,8,10}, {9,12,15},  {12, 16, 20}, etc., family.  All the family members can be divided by an integral value to get {3, 4, 5}.  If you were to graph these points on a x,y-grid, the points would lie on the line defined by y = f(x) = 4x / 3.  So, the SlopeHi variable refers the slope of the line for {3, 4, 5}.  The solution for {4, 3, 5} , while equivalent to {3, 4, 5} in the Pythagorean Theorem, lines on the line y = f(x) = 3x / 4.  (SlopeLo variable.)  It should be noted that NOT just any line on the x,y-grid has an integral solution to the Pythagorean Theorem.

I have written the program to find the value of x as the lowest of the solution.  That is:  the {3, 4, 5} solution is shown but not the {4, 3, 5} solution.  The program writes out its findings to a text data file on disk.

Dee

Sam Steele

  • Guest
Re: A simple console program for Pythagorean Primitives
« Reply #1 on: February 20, 2016, 07:56:06 AM »
Beautiful code. Easy to understand.
You could expand it to higher dimensions and use it to find a counter-example to Andrew Wiles’s proof of Fermat’s Last Theorem!

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: A simple console program for Pythagorean Primitives
« Reply #2 on: February 20, 2016, 06:22:54 PM »
Nice  :)
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Grincheux

  • Guest
Re: A simple console program for Pythagorean Primitives
« Reply #3 on: February 20, 2016, 08:00:52 PM »
There's a long time I had not seen such a clear code even if I don't understand. mathematics and I are not friends... :-[

defrancis7

  • Guest
Re: A simple console program for Pythagorean Primitives
« Reply #4 on: December 14, 2016, 05:22:16 PM »
Thanks guys for the kind praise.  I am sorry I have not looked sooner to see if anyone had commented.