Skip to content

Commit a9697fc

Browse files
committed
solved problem 34 for euelr
1 parent 4123799 commit a9697fc

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

categories/euler/prob034-quinny.pl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

t/categories/euler.t

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,15 @@ if False {
620620
}, "prob189";
621621
}
622622

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+
623632
#| check examples provided by the given authors
624633
sub check-example-solutions($problem, $expected-output, @authors) {
625634
for @authors -> $author {

0 commit comments

Comments
 (0)