From ecb58863c7dc0185708ea52fc6ca956c0f8fb1f7 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 15 May 2009 19:21:30 -0500 Subject: solution 23 --- 023.pl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 023.pl diff --git a/023.pl b/023.pl new file mode 100755 index 0000000..c145fb7 --- /dev/null +++ b/023.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Math::Factor::XS qw/factors/; +use List::Util qw/sum/; + +sub abundant { + my ($n) = @_; + return 1 + (sum(factors($n)) || 0) > $n; +} + +my @abundant = grep { abundant($_) } 1..28123; +my %sums; +A: for my $a (@abundant) { + for my $b (@abundant) { + my $n = $a + $b; + next A if $n > 28123; + $sums{$n} = 1; + } +} +my $total = 0; +for my $n (1..28123) { + $total += $n unless exists $sums{$n}; +} +print "$total\n"; -- cgit v1.2.3