Skip to content

Commit 6e8e53f

Browse files
committed
[euler] problem 30 solution
1 parent 230d296 commit 6e8e53f

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

categories/euler/prob030-andreoss.pl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use v6;
2+
3+
=begin pod
4+
5+
=TITLE Digit fifth powers
6+
7+
=AUTHOR Andrei Osipov
8+
9+
Surprisingly there are only three numbers that can be written as the
10+
sum of fourth powers of their digits:
11+
12+
1634 = 1⁴ + 6⁴ + 3⁴ + 4⁴
13+
8208 = 8⁴ + 2⁴ + 0⁴ + 8⁴
14+
9474 = 9⁴ + 4⁴ + 7⁴ + 4⁴
15+
16+
As 1 = 14 is not a sum it is not included.
17+
18+
The sum of these numbers is 1634 + 8208 + 9474 = 19316.
19+
20+
Find the sum of all the numbers that can be written as the sum of
21+
fifth powers of their digits.
22+
23+
=end pod
24+
25+
sub get-numbers(:$start = 10, :$depth = 6, *@a) {
26+
return @a.item unless $depth;
27+
do for ^$start -> \x {
28+
get-numbers start => x + 1,
29+
depth => $depth -1, |@a,x;
30+
}
31+
}
32+
33+
say [+] -1, gather for get-numbers() -> @a {
34+
my $v = [+] @a »**» 5;
35+
my $b = [+] $v.comb »**» 5;
36+
take $b if $v == $b;
37+
}
38+

t/categories/euler.t

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use v6;
22

33
use Test;
44

5-
plan 54;
5+
plan 55;
66

77
subtest {
88
plan 5;
@@ -311,6 +311,14 @@ subtest {
311311
check-example-solutions($problem, $expected-output, @authors)
312312
}, "prob029";
313313

314+
subtest {
315+
plan 1;
316+
317+
my $problem = "prob030";
318+
my @authors = <andreoss>;
319+
check-example-solutions($problem, $expected-output, @authors)
320+
}, "prob030";
321+
314322
subtest {
315323
plan 1;
316324

0 commit comments

Comments
 (0)