Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 23 lines (19 sloc) 0.405 kb
329dad0 @jtpalmer Problem 34, Perl 5.
authored
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use 5.010;
5 use List::Util qw(sum);
6
7 sub factorial {
8 my ($n) = @_;
9 return 1 if $n <= 1;
10 return $n * factorial( $n - 1 );
11 }
12
13 my %factorial = map { $_ => factorial($_) } 0 .. 9;
14
15 my $sum;
16 my $n = 10;
17 while ( length($n) * $factorial{9} > $n ) {
18 my $s = sum map { $factorial{$_} } split( //, $n );
19 $sum += $n if $n == $s;
20 $n++;
21 }
22 say $sum;
Something went wrong with that request. Please try again.