Skip to content

Instantly share code, notes, and snippets.

@ichirin2501
Created August 25, 2012 04:51
Show Gist options
  • Save ichirin2501/3460941 to your computer and use it in GitHub Desktop.
Save ichirin2501/3460941 to your computer and use it in GitHub Desktop.
Project Euler 34
#!/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