Permalink
Browse files

Adding answer to euler #3

  • Loading branch information...
1 parent 1161e69 commit 73de98f77c7636615a608965f6c964d335b613a0 @eric256 eric256 committed Dec 22, 2008
Showing with 28 additions and 0 deletions.
  1. +1 −0 euler/README
  2. +27 −0 euler/prob003-eric256.pl
View
1 euler/README
@@ -1,5 +1,6 @@
Project Euler
=============
+http://projecteuler.net/
This is a directory to post answers to project euler questions.
View
27 euler/prob003-eric256.pl
@@ -0,0 +1,27 @@
+use v6;
+
+sub is_prime ($num) {
+ for (2..^$num) {
+ return 0 unless $num % $_;
+ }
+ return 1;
+};
+
+class Primes {
+ has $.current = 0;
+
+ method next {
+ $.current++;
+ $.current++ until is_prime($.current);
+ return $.current;
+ }
+}
+
+my $prime = Primes.new();
+my $number = 600851475143;
+while ($number > 1) {
+ if !($number % $prime.next) {
+ $number /= $prime.current;
+ say "Found: ", $prime.current;
+ }
+}

0 comments on commit 73de98f

Please sign in to comment.