Commits

Shlomi Fish committed bb5d0ac

Add 142.pl - it's too slow.

Comments (0)

Files changed (2)

project-euler/142/142.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+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);
+}
+
+foreach my $x (1 .. 1_000_000)
+{
+    Y_LOOP:
+    foreach my $y (1 .. $x-1)
+    {
+        if (!is_square($x+$y) or !is_square($x-$y))
+        {
+            next Y_LOOP;
+        }
+        print "Reached X=$x Y=$y\n";
+        foreach my $z (1 .. $y-1)
+        {
+            if (is_square($y+$z) and 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)