Archive for the ‘Uncategorized’ Category

Solution Project Euler Problem 12 Java

Tuesday, January 6th, 2009

I have solved problem 12 of Project Euler. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 12 is here

Problem012.java

Solution Project Euler Problem 10 Java

Sunday, December 28th, 2008

I have solved problem 10 of Project Euler. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 10 is here

Problem010_SieveOfErastothenes.java

Solution Problem 9 Project Euler

Monday, December 22nd, 2008

I have solved problem 9 of Project Euler. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 9 is here

Problem009.java

Solution Problem 8 Project Euler

Sunday, December 21st, 2008

I have solved problem 8 of Project Euler. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 8 is here

Problem008.java

Solution Problem 7 Project Euler

Wednesday, December 10th, 2008

I have solved problem 7 of Project Euler. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 7 is here

Problem007.java

Solution Problem 6 Project Euler

Monday, December 8th, 2008

I have solved problem 6 of Project Euler. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 6 is here

Problem006.java

The solution only has the optimization of finding the sum of the nth number through the formula

sum(n) = n * ( n + 1) / 2

Hope the solution is understandable. If not, don’t hesitate to put a comment.

Solution Problem 5 Project Euler

Friday, December 5th, 2008

I have solved problem 5 of Project Euler. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 5 is here

Problem005.java

A brute force approach to solving this problem. The solution has a minor optimization which is to increase the outer loop by 20 (the “limit” variable) in each iteration.

Hope the solution is understandable. If not, don’t hesitate to put a comment.

Solution Problem 4 Project Euler

Tuesday, November 25th, 2008

I have solved problem 4 of Project Euler. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 4 is here

Problem004.java

The solution is a brute force approach. I initialize two numbers to 999 and then iterate down on each of them separately until we reach zero on both. At this point we should have the two three digit numbers that make up the largest palindrome.

Hope the solution is understandable. If not, don’t hesitate to put a comment.

Solution to Problem 3 Project Euler

Thursday, November 6th, 2008

I have solved problem 3 of the Project Euler using java. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 3 is here

Problem003.java

Below I will try to describe the algorithm I used to solve the problem:

a) We will iterate starting at 3 to the number numberToGetLargestPrimeFactor / largestPrimeFactor . Where the numberToGetLargestPrimeFactor is initialized to 600851475143L and largestPrimeFactor is the largest prime number calculated up to that point in the iteraton, it is initialized at 1.

b) At each iteration we will check if the i divides numberToGetLargestPrimeFactor exactly.

c) If i divides numberToGetLargestPrimeFactor exactly then we will find out if i is a prime number.

d) To check if i is a prime number we do it by trying to divide i between the different numbers in the list of prime numbers. If it is divided by one of them then it means that i is not a prime number.

e) If i is a primer number then we store it in the list of primes. And we make largestPrimeFactor equal to the value of i.

Hope this helps in understanding the algorithm.

Solution to Project Euler Problem 2 Using Java

Sunday, October 19th, 2008

I have solved problem 2 of Project Euler using java. I created a google code hosted project here where you can check out the solutions to the problems I have solved. In particular the solution to problem 2 is here

Problem 2

What I used for solving the problem was a procedural implementation of the fibonacci series. If you program in java you always have to remember that primitives are faster than Number objects. BTW the solutions is a brute force approach, but it runs pretty fast in Java.