# HG changeset patch # User Shlomi Fish # Date 1331559279 -7200 # Node ID 431d94067f9a161c70dd05103790cb9599910ad8 # Parent c9f3e67e0eaebf7cf006f325847c11cf0b4abd4b Add the (too slow so far) solution to Euler #138. diff --git a/project-euler/138/138-analysis.txt b/project-euler/138/138-analysis.txt --- a/project-euler/138/138-analysis.txt +++ b/project-euler/138/138-analysis.txt @@ -10,8 +10,12 @@ Find ∑ L for the twelve smallest isosceles triangles for which h = b ± 1 and b, L are positive integers. [/QUOTE] -h = b +/- 1. +h = b ± 1. -b/2 = h/2 +/- 1/2. +b/2 = h/2 ± 1/2. L = sqrt [ h^2 + (h/2 +/- 1/2)^2 ] = sqrt [ 5/4h^2 + 1/4 +/- h/2 ] + +a = h/2 + +L = sqrt[ 5a^2 + 1/4 ± a ] diff --git a/project-euler/138/euler-138-1.pl b/project-euler/138/euler-138-1.pl new file mode 100644 --- /dev/null +++ b/project-euler/138/euler-138-1.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Math::BigRat lib => 'GMP'; + +my \$h = 2; + +my \$c2 = Math::BigRat->new('5/4'); +my \$c0 = Math::BigRat->new('1/4'); +my \$c1_p = Math::BigRat->new('1/2'); +my \$c1_m = Math::BigRat->new('-1/2'); + +while (1) +{ + foreach my \$c1 (\$c1_m, \$c1_p) + { + my \$L = (\$c0 + \$h*(\$c1 + \$h*\$c2))->bsqrt(); + my \$L_int = \$L->as_int(); + if (\$L_int == \$L) + { + print "Found \$L_int\n"; + } + } +} +continue +{ + \$h+=2; +}