Skip to content

Instantly share code, notes, and snippets.

@ichirin2501
Created August 23, 2012 13:36
Show Gist options
  • Save ichirin2501/3436660 to your computer and use it in GitHub Desktop.
Save ichirin2501/3436660 to your computer and use it in GitHub Desktop.
Project Euler 32
#!/usr/bin/perl
use warnings;
use strict;
use List::Util qw/sum/;
my %S = ();
for(my $i=1000; $i<=9999; $i++){
for(my $j=1; $j*$j<=$i; $j++){
if( $i % $j == 0 ){
my $k = $i / $j;
my %h;
@h{(split(//,$i),split(//,$j),split(//,$k))} = ();
if( !exists($h{0}) && scalar(keys %h) == 9 ){
$S{$i} = 1;
}
}
}
}
print sum(keys %S),"\n";
# => 45228
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment