Skip to content

Commit ff087ef

Browse files
committed
[euler/prob009] add O(N) version
1 parent 0403454 commit ff087ef

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

euler/prob009-gerdr.pl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use v6;
2+
3+
sub first-triple(\N) {
4+
for 1..(N div 3) -> \a {
5+
my \u = N * (N - 2 * a);
6+
my \v = 2 * (N - a);
7+
8+
if u %% v {
9+
my \b = u div v;
10+
my \c = N - a - b;
11+
return a, b, c;
12+
}
13+
}
14+
}
15+
16+
say [*] first-triple(1000);

0 commit comments

Comments
 (0)