Commits

Shlomi Fish committed d02e3ef Merge

Merged

Comments (0)

Files changed (2)

project-euler/142/142.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use integer;
+
+use IO::All;
+
+# use Math::BigInt lib => 'GMP';
+
+sub is_square
+{
+    my $n = shift;
+
+    # my $root = int($n->copy->bsqrt());
+    my $root = int(sqrt($n));
+
+    return ($root * $root == $n);
+}
+
+my $milestone_step = 10_000;
+my $next_milestone = $milestone_step;
+
+foreach my $x (1 .. 1_000_000)
+{
+    my $x_diff = 1;
+    Y_LOOP:
+    for (my $y = $x-1 ; $y > 0 ; $y -= ($x_diff += 2))
+    {
+        if (!is_square($x+$y))
+        {
+            next Y_LOOP;
+        }
+        if ($x >= $next_milestone)
+        {
+            print "Reached X=$x Y=$y\n";
+            $next_milestone += $milestone_step;
+        }
+
+        my $y_diff = 1;
+        for (my $z = $y-1 ; $z > 0 ; $z -= ($y_diff += 2))
+        {
+            if (is_square($y+$z) and is_square($x-$z)
+                    and is_square($x+$z))
+            {
+                print "Found X=$x Y=$y Z=$z S=@{[$x+$y+$z]}\n";
+                exit(0);
+            }
+        }
+    }
+}

project-euler/142/euler-142-analysis.txt

-Find the smallest x + y + z with integers x > y > z > 0 such that 
+Find the smallest x + y + z with integers x > y > z > 0 such that
 x + y, x − y, x + z, x − z, y + z, y − z are all perfect squares.
 
 (x - y) + (y - z) = (x - z)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.