Permalink
Browse files

Project Euler Problem #10

This shows how to solve Project Euler Problem #10 with Math::Primality.
  • Loading branch information...
1 parent 08dd271 commit 43d0961730f98629c937c4b2c84a1984b7c6d647 @leto committed Jul 9, 2009
Showing with 15 additions and 0 deletions.
  1. +15 −0 examples/project_euler/10/project_euler_10.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Math::Primality qw/is_prime/;
+$|++;
+
+my $limit = shift || 2_000_000;
+my $sum = 5; # 2 + 3
+
+for my $n (5..$limit) {
+ next unless ( $n % 2 ); # don't check even numbers
+ $sum += $n if is_prime($n);
+}
+print "sum of first $limit primes = $sum\n";

0 comments on commit 43d0961

Please sign in to comment.