September 2010
M T W T F S S
« Dec    
 12345
6789101112
13141516171819
20212223242526
27282930  

Categories

Project Euler Problem 12 in Java

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …

Let us list the factors of [...]

Project Euler Problem 2 in Java

?View Code JAVA1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
public class Problem2
 
{
 
private static double sum = 0;
private static double number[] = new double[2];
private static double swap;
 
 
public static void main(String args[])
{
number[0]=1;
[...]

Project Euler Problem 1 in Java

I decided to post some older solutions I have. I had posted these on my forum; however it does not appear on the search engine so I think this will be more convenient.

?View Code JAVA1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class Problem1
{
public static void main(String args[])
{
[...]

Project Euler Problem 61 in Java

 Show Problem 61
This gave me a headache. I was about to give up when I recalled that recursion is a very powerful tool and is very suitable for this question. The code does not look so pretty or concise but it is really powerful. I think you can figure out easily what I tried to [...]

Project Euler Problem 72 in Java

Finally, I have found a very efficient answer for Problem 72. It runs under 1 seconds. It uses prime sieve of Eratosthenes.

Here is the code in Java

?View Code JAVA1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Arrays;
 
public class Problem72 {
 
public static void main(String args[])
{
int n=1000000;
int[] phi = new int[n+1];
for (int i=0; i<n+1; i++)
phi[i]=i;
 
boolean[] p = new boolean[n+1];
Arrays.fill(p, true);
p[0]=false;
p[1]=false;
for (int i=2; i<=n; i++)
{
 
if [...]

Project Euler Problem 102 in Java

Show Problem 102
First of all we need a method to check whether a point is in the triangle or not. This site has some useful info regarding this issue. Actually, it is for three dimension but two dimensions is applicable if we set the third dimension to zero always. All we need to code is [...]

Project Euler Problem 62 in Java

Show Problem 62

For this one I used a map. I calculated the cubes for integers till 10000. Then I sorted every cube. Using a hashmap I calculated the frequency of each sort. If the freq is 5, that gives us the combination. Using another hashmap I associated the integer before cube calculation with the combination. [...]

Project Euler Problem 112 in Java

Show Problem 112

This one is very easy if you know the trick. Here is the trick. If you sort a number ascendingly and if it is still equals the same number then it is an increasing one. If you sort it descendingly and is still the same number it is a decreasing one. If neither [...]

Project Euler Problem 85 in Java

This problem was fun. You have to come up with a way to count the rectangles in a rectangular grid. I used a four nested loop to count the rectangles. First two loops specify the grid size. Then the other two nested loops do the actual work. I assumed that the answer would be in [...]

Project Euler Problem 74 in Java

When I first solved this problem I used BigIntegers. It took about 30 minutes to find the answer. The reason for that is I used BigIntegers and a binarysort in a loop. In fact the numbers used do not exceed integer limit so there is no need to use BigIntegers. So I present the more [...]