Permalink
Browse files

Euler problem #3

 Added Euler problem #3 and added new line for euler_2
  • Loading branch information...
itcharlie committed Nov 8, 2011
1 parent 670e21c commit 84127e499a24e9e9b8029b37e0356d4fe9fc5fde
Showing with 38 additions and 1 deletion.
  1. +1 −1 prj_euler/euler_2.pl
  2. +37 −0 prj_euler/euler_3.pl
View
@@ -30,4 +30,4 @@
}
print Dumper(\@list_term);
-print eval ( join ( '+' , @list_term) ) ;
+print eval ( join ( '+' , @list_term) ) . "\n";
View
@@ -0,0 +1,37 @@
+use strict;
+use Data::Dumper;
+
+# Euler problem #3:
+# The prime factors of 13195 are 5, 7, 13 and 29.
+# What is the largest prime factor of the number 600851475143 ?
+# Definition as stated from this site ( http://www.mathsisfun.com/prime_numbers.html )# Prime Numbers can be divided evenly only by 1 or itself.
+# And it must be a whole number greater than 1.
+
+# My approach to this problem is to list a few prime numbers
+# and using this list I will attempt to determine the prime numbers
+# for 600851475143
+my @prime_num;
+
+
+for my $term ( 2 ... 1000) {
+ is_prime($term);
+}
+
+print Dumper(\@prime_num);
+sub is_prime{
+ my $num = shift;
+
+ # Check if the number is not 2 and can be divided by 2
+
+ if ( ( ($num/2) !~ /\D/ ) and $num != 2 ) {
+ next;
+ # Check if the number is not 3 and can be divided by 3
+ } elsif ( (($num /3) !~ /\D/ ) and $num !=3 ) {
+ next;
+ # Check if the number is not 5 and can it be divided by 5
+ } elsif ( ( ($num /5) !~ /\D/) and $num != 5 ) {
+ next;
+ } else {
+ push( @prime_num , $num) ;
+ };
+ }

0 comments on commit 84127e4

Please sign in to comment.