Happy Pythagorean Theorem Day folks and a Challenge!

Pythagorean Theorem Day is celebrated when the sum of the squares of the first two parts of the date equals the square of the last part. The last Pythagorean Theorem Day was August 15, 2017 (15² + 8² = 17²).
Today - December 16, 2020 (16² + 12² = 20²).

Challenge

Write a program to calculate the next occurrence :slight_smile:

2 Likes

I’ve got the next date, but my code is too rough to share.

24 Jul 2025

2 Likes

…and the final one for this century is…

Saturday - October 24, 2026 ( 10² + 24² = 26² ).

If anyone is interested in the next century
then look out for these similar dates…

Friday - April 3, 2105 ( 3² + 4² = 5² ).
Wednesday - August 6, 2110 ( 6² +8² = 10² ).
Tuesday - December 5, 2113 ( 5² + 12² = 13² ).
Monday - December 9, 2115 ( 9² + 12² = 15² ).
Sunday - August 15, 2117 ( 8² + 15² = 17² ).
Saturday - December 16, 2120 ( 12² + 16² = 20² ).
Tuesday - July 24, 2125 ( 7² + 24² = 25² ).
Thurday - October 24, 2126 ( 10² + 24² = 26² ).

Luckily for me my birthday is a primitive Pythagorean triple. :biggrin:

Further reading:-

The Two-Fractions method of generating Pythagorean Triples

coothead

2 Likes

@coothead, Best wishes on your Birthday.

Notice I found another Pythagorean Date using this method:

PHP has a handy date() function that output a string date depending upon the second integer time. The time is the number of seconds since “Jan 1st 1970”:

https://www.php.net/manual/en/function.date

and format specifiers

https://www.php.net/manual/en/datetime.formats.time.php

<?php 
  define('SECONDS_PER_DAY', 60*60*24) ;

  $now = 1607923804; // 3 days before last Pythagorean date

  for($i2=0 ; $i2<39999; $i2++):
    $y = (int) date('y', $now);
    $m = (int) date('m', $now);
    $d = (int) date('d', $now);

    if( (($d * $d) + ($m * $m)) === $y * $y):
        echo '<p><strong>';
          echo date('D, M dS Y', $now);
          // echo ' </strong> ==> ' .$d*$d  .'+'  .$m*$m.' === ' .$y*$y;
          echo ' </strong> ==> ' .$m*$m  .'+'  .$d*$d.' === ' .$y*$y;
        echo '</p>';
    endif;
    $now += SECONDS_PER_DAY;
  endfor;  

Output:

[quote]
Wed, Dec 16th 2020 ==> 144+256 === 400

Thu, Jul 24th 2025 ==> 49+576 === 625

Sat, Oct 24th 2026 ==> 100+576 === 676

Wed, Mar 04th 2105 ==> 9+16 === 25

Fri, Apr 03rd 2105 ==> 16+9 === 25

Sun, Jun 08th 2110 ==> 36+64 === 100

Wed, Aug 06th 2110 ==> 64+36 === 100

Fri, May 12th 2113 ==> 25+144 === 169

Tue, Dec 05th 2113 ==> 144+25 === 169

Thu, Sep 12th 2115 ==> 81+144 === 225

Mon, Dec 09th 2115 ==> 144+81 === 225

Sun, Aug 15th 2117 ==> 64+225 === 289

Mon, Dec 16th 2120 ==> 144+256 === 400

Tue, Jul 24th 2125 ==> 49+576 === 625

Thu, Oct 24th 2126 ==> 100+576 === 676[/quote]

Well, some logic:

  1. Months are bounded 1-12; Days are bounded 1-31;
  2. You cannot add two positive numbers and end up at a value less than either of the original numbers;
  3. The squares of two positive numbers share the magnitude comparator of that of its unsquared form. (IE: a^2 > b^2 if a > b)

So you can streamline your search a little bit before you even start just from logic:

  • Any two-digit year that is less than 31 will have limit-bound impossibilities that don’t need to be checked (If looking for Triple Dates in the year 2020, you dont need to check March 31 - it can’t be a Triple date because 31 > 20.)
  • The maximal values of month and day (December 31) have a value 1105 - or 33 and change when rooted. Thus, no Triple dates will ever exist in 2-digit years higher than 33.
  • There is no 0’th month and 0th day, so the century year can immediately be written off.
  • (I guess this one also applies) Since you’re using a 2 digit year, this list is not bound by the century; that is to say, every December 16, XX20, will be a Triple Date.

So you’ve got 3 years where every date needs to be checked (31, 32, 33), and then a cascading decrease in dates that need to be checked from 30 to 1 (Where 1 only has a single day that needs to be checked, January 1st).

There’s probably a rule of logic i’m missing regarding m+d <relation to> y that would narrow the pattern as well, but its 3 am and my brain isnt bringing it forward.

1 Like

I think that you are mistaken. :eek:

Only the first four primitive Pythagorean triples
can be used…

  1. ( 3, 4, 5 )
  2. ( 5, 12, 13 )
  3. ( 7, 24, 25 )
  4. ( 8, 15, 17 )

…with four non-primitive Pythagorean triples
from the first two…

  1. ( 6, 8, 10 )
  2. ( 9, 12, 15 )
  3. ( 12, 16, 20 )
  4. ( 10, 24, 26 )

The first two numbers of the triple must contain
one number less than or equal to 31 and one
number less than or equal to 12.

There are no other Pythagorean triples that fit
those conditions.

coothead

1 Like

BUT, these are not Combinations, they are Permutations (the first two numbers are not just ‘two numbers’, they are a Month and Day, and thus are not reducible). Thus, 6,8,10 and 8,6,10 are both valid values.

Applying Permutation rather than Combination adds:
(4,3,5)
(12,5,13)
(8,6,10)
(12,9,15)

Thus, the full set has magnitude 12, which is the date list that John’s code spat out. (the last 3 are repetitions of the first 3, just a century later)

1 Like

Okay, well this is my code

<?php

for ($i = 1; $i <= 31; $i++) {
  for ($j = 1; $j <= 12; $j++) {
    $ij = ($i * $i) + ($j * $j);
    $sq = sqrt($ij);
    if ((int)$sq * (int)$sq == $ij) {
      if (checkdate($j, $i, (2000 + $sq))) {
        echo $i, '/', $j, '/', (2000 + $sq), "\n";
      }
    }
  }
}

2 Likes

Hi there m_hutley,

I see what you mean. :winky:

These four primitive of my list…

  1. ( 3, 4, 5 )
  2. ( 5, 12, 13 )
  3. ( 6, 8, 10 )
  4. ( 9, 12, 15 )

…can be reversed to give four more dates in the century’.

Sorry @John_Betong for misunderstanding your post. :nono:

coothead

1 Like

Just been playng with your code, pleased to say the results are the same and also it is fast!!!.

Well done :slight_smile:

1 Like

I agree. Relatively straightforward, but with a slight problem that didnt actually come up in this code - you’re forcing a floor on the square root of $ij by making it an int, and potentially introducing rounding error.

If sqrt($ij) (“c” in a^2+b^2 = c^2) is not an integer already, it cannot be a Pythagorean Triple. Immediately discard it.

EDIT: That’s what you’re trying to do with re-squaring it… but wouldnt it be simpler to compare (int)$sq to $sq?

2 Likes

Good thinking, Batman.