Skip to content

Commit f423a3c

Browse files
committed
solved project euler 39
1 parent 1d0e3ae commit f423a3c

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

categories/euler/prob39-quinny.pl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use v6;
2+
3+
=begin pod
4+
5+
=TITLE Integer right triangles
6+
7+
=AUTHOR Quinn Perfetto
8+
9+
L<https://projecteuler.net/problem=39>
10+
11+
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.
12+
13+
{20,48,52}, {24,45,51}, {30,40,50}
14+
15+
For which value of p ≤ 1000, is the number of solutions maximised?
16+
17+
=end pod
18+
19+
sub isTriple($a, $b, $c) {
20+
($a * $a) + ($b * $b) == ($c * $c);
21+
}
22+
23+
sub solutionsFor($p) {
24+
[+] gather for 1 .. $p -> $i {
25+
for ($i + 1) .. ($p - $i) -> $j {
26+
my $k = $p - $i - $j;
27+
take isTriple($i, $j, $k)
28+
}
29+
}
30+
}
31+
32+
my $max = 0;
33+
my $perim = 0;
34+
for 3 .. 1000 {
35+
my $check = solutionsFor $_;
36+
if $check > $max {
37+
$max = $check;
38+
$perim = $_;
39+
}
40+
}
41+
42+
say $perim;

t/categories/euler.t

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@ unless $skip {
374374
}, "prob034";
375375
}
376376

377+
skip("prob039 takes too long in tests");
378+
unless $skip {
379+
subtest {
380+
plan 1;
381+
my $problem = "prob039";
382+
my @authors = <quinny>;
383+
my $expected-output = 840;
384+
385+
check-example-solutions($problem, $expected-output, @authors)
386+
}, "prob039";
387+
}
388+
377389
subtest {
378390
plan 1;
379391

0 commit comments

Comments
 (0)