Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #32 from Quinny/master
solved project euler 39
  • Loading branch information
zoffixznet committed Oct 7, 2015
2 parents 1d0e3ae + f423a3c commit c3a6d2e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
42 changes: 42 additions & 0 deletions categories/euler/prob39-quinny.pl
@@ -0,0 +1,42 @@
use v6;

=begin pod
=TITLE Integer right triangles
=AUTHOR Quinn Perfetto
L<https://projecteuler.net/problem=39>
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximised?
=end pod

sub isTriple($a, $b, $c) {
($a * $a) + ($b * $b) == ($c * $c);
}

sub solutionsFor($p) {
[+] gather for 1 .. $p -> $i {
for ($i + 1) .. ($p - $i) -> $j {
my $k = $p - $i - $j;
take isTriple($i, $j, $k)
}
}
}

my $max = 0;
my $perim = 0;
for 3 .. 1000 {
my $check = solutionsFor $_;
if $check > $max {
$max = $check;
$perim = $_;
}
}

say $perim;
12 changes: 12 additions & 0 deletions t/categories/euler.t
Expand Up @@ -374,6 +374,18 @@ unless $skip {
}, "prob034";
}

skip("prob039 takes too long in tests");
unless $skip {
subtest {
plan 1;
my $problem = "prob039";
my @authors = <quinny>;
my $expected-output = 840;

check-example-solutions($problem, $expected-output, @authors)
}, "prob039";
}

subtest {
plan 1;

Expand Down

0 comments on commit c3a6d2e

Please sign in to comment.