File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ use v6 ;
2
+
3
+ = begin pod
4
+
5
+ = TITLE Digit factorials
6
+
7
+ = AUTHOR Quinn Perfetto
8
+
9
+ L < https://projecteuler.net/problem=34 >
10
+
11
+ 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
12
+
13
+ Find the sum of all numbers which are equal to the sum of the factorial of their digits.
14
+
15
+ Note: as 1! = 1 and 2! = 2 are not sums they are not included.
16
+
17
+ Expected result: 40730
18
+
19
+ = end pod
20
+
21
+ sub fact ($ n ) {
22
+ [* ] 1 .. $ n ;
23
+ }
24
+
25
+ sub factDigits ($ n is copy ) {
26
+ [+ ] gather while $ n > 0 {
27
+ take fact $ n % 10 ;
28
+ $ n div = 10 ;
29
+ }
30
+ }
31
+
32
+ say [+ ] gather for 3 ... 40586 {
33
+ take $ _ if factDigits($ _ ) == $ _
34
+ }
Original file line number Diff line number Diff line change @@ -620,6 +620,15 @@ if False {
620
620
}, " prob189" ;
621
621
}
622
622
623
+ subtest {
624
+ plan 1 ;
625
+ my $ problem = " prob034" ;
626
+ my @ authors = <quinny >;
627
+ my $ expected-output = 40730 ;
628
+
629
+ check-example-solutions($ problem , $ expected-output , @ authors )
630
+ }, " prob034" ;
631
+
623
632
# | check examples provided by the given authors
624
633
sub check-example-solutions ($ problem , $ expected-output , @ authors ) {
625
634
for @ authors -> $ author {
You can’t perform that action at this time.
0 commit comments