June 2009
M T W T F S S
« Mar   Aug »
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

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 72 in MATLAB

Show Problem 72
This code took about 30 minutes to run on my computer. I tried to implement the same logic in Java; however, it took hours to get an answer.However, an efficient Java solution with prime sieving is HERE.(Runs under 1 seconds). Here is the logic the totient function of a number gives how many [...]

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 [...]

Project Euler Problem 65 in Java

Hi everyone. It has been a while. In meantime I have discovered how fun it was to solve projecteuler.net problems. From now on I decided to publish my answers here. Actually, I was publishing them in the forum section of javaist. However, there has been some spamming there so I decided to carry my answers [...]