File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change 2
2
3
3
use Test ;
4
4
5
- plan 54 ;
5
+ plan 55 ;
6
6
7
7
subtest {
8
8
plan 5 ;
@@ -311,6 +311,14 @@ subtest {
311
311
check-example-solutions($ problem , $ expected-output , @ authors )
312
312
}, " prob029" ;
313
313
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
+
314
322
subtest {
315
323
plan 1 ;
316
324
You can’t perform that action at this time.
0 commit comments