Created
August 25, 2012 04:51
-
-
Save ichirin2501/3460941 to your computer and use it in GitHub Desktop.
Project Euler 34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
use List::Util qw/sum/; | |
sub fact{ | |
my $n = shift; | |
return 1 if $n == 0; | |
return $n * &fact($n - 1); | |
} | |
# 9!+9!+9!+9!+9!+9!+9! = 2540160 | |
my @f = map{ &fact($_) } 0..9; | |
print sum(grep{ my $t = $_; $t == sum(map{$f[$_]}split(//,$t)) } 3..2540160),"\n"; | |
# => 40730 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment