-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solve many problems in java (22 is expected failure)
- Loading branch information
1 parent
95de053
commit 5703084
Showing
20 changed files
with
335 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
utils.cs | ||
======= | ||
======== | ||
|
||
View source code :source:`csharp/include/utils.cs` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Java Implementation of Problem 2 | ||
================================ | ||
|
||
View source code :source:`java/src/main/java/euler/p0002.java` | ||
|
||
.. java:class:: p0002 implements Euler.IEuler | ||
.. java:method:: Object answer() | ||
.. literalinclude:: ../../java/src/main/java/euler/p0002.java | ||
:language: java | ||
:linenos: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Java Implementation of Problem 4 | ||
================================ | ||
|
||
View source code :source:`java/src/main/java/euler/p0004.java` | ||
|
||
.. java:class:: p0004 implements Euler.IEuler | ||
.. java:method:: Object answer() | ||
.. literalinclude:: ../../java/src/main/java/euler/p0004.java | ||
:language: java | ||
:linenos: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Java Implementation of Problem 6 | ||
================================ | ||
|
||
View source code :source:`java/src/main/java/euler/p0006.java` | ||
|
||
.. java:class:: p0006 implements Euler.IEuler | ||
.. java:method:: Object answer() | ||
.. literalinclude:: ../../java/src/main/java/euler/p0006.java | ||
:language: java | ||
:linenos: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Java Implementation of Problem 9 | ||
================================ | ||
|
||
View source code :source:`java/src/main/java/euler/p0009.java` | ||
|
||
.. java:class:: p0009 implements Euler.IEuler | ||
.. java:method:: Object answer() | ||
.. literalinclude:: ../../java/src/main/java/euler/p0009.java | ||
:language: java | ||
:linenos: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Java Implementation of Problem 22 | ||
================================= | ||
|
||
View source code :source:`java/src/main/java/euler/p0022.java` | ||
|
||
.. java:class:: p0022 implements Euler.IEuler | ||
.. java:method:: Object answer() | ||
.. literalinclude:: ../../java/src/main/java/euler/p0022.java | ||
:language: java | ||
:linenos: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Utilities.java | ||
============== | ||
|
||
View source code :source:`java/src/main/java/euler/lib/Utilities.java` | ||
|
||
.. java:class:: Utilities | ||
.. java:method:: static string getDataFileText(string name) | ||
.. java:method:: static byte[] getDataFileBytes(string name) | ||
.. java:method:: static object getAnswer(ulong n) | ||
.. literalinclude:: ../../java/src/main/java/euler/lib/Utilities.java | ||
:language: java | ||
:linenos: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Project Euler Problem 2 | ||
This is a port of the optimized version found in python. For a proof of why this | ||
works, see that implementation | ||
Problem: | ||
Each new term in the Fibonacci sequence is generated by adding the previous two | ||
terms. By starting with 1 and 2, the first 10 terms will be: | ||
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... | ||
By considering the terms in the Fibonacci sequence whose values do not exceed | ||
four million, find the sum of the even-valued terms. | ||
*/ | ||
package euler; | ||
|
||
public class p0002 implements IEuler { | ||
@Override | ||
public Object answer() { | ||
int answer = 0, | ||
i = 2, | ||
j = 8, | ||
tmp = 0; | ||
|
||
while (i < 4000000) { | ||
answer += i; | ||
tmp = 4 * j + i; | ||
i = j; | ||
j = tmp; | ||
} | ||
|
||
return answer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Project Euler Problem 4 | ||
I couldn't figure out how to do this as efficiently as I would have liked. I am | ||
SURE that there is a better way to check if a number is a palindrome, but I | ||
could not think of one. | ||
Problem: | ||
A palindromic number reads the same both ways. The largest palindrome made from | ||
the product of two 2-digit numbers is 9009 = 91 × 99. | ||
Find the largest palindrome made from the product of two 3-digit numbers. | ||
*/ | ||
package euler; | ||
|
||
public class p0004 implements IEuler { | ||
private boolean IsPalindrome(int x) { | ||
String rep = Integer.toString(x); | ||
int length = rep.length(); | ||
for (int i = 0; i < length; i += 1) { | ||
if (rep.charAt(i) != rep.charAt(length - i - 1)) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public Object answer() { | ||
int answer = 0; | ||
for (int v = 101; v < 1000; v++) { | ||
for (int u = 100; u < v; u++) { | ||
int p = u * v; | ||
if (IsPalindrome(p) && p > answer) | ||
answer = p; | ||
} | ||
} | ||
|
||
return answer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Project Euler Problem 6 | ||
This turned out to be really easy | ||
Problem: | ||
The sum of the squares of the first ten natural numbers is, | ||
1**2 + 2**2 + ... + 10**2 = 385 | ||
The square of the sum of the first ten natural numbers is, | ||
(1 + 2 + ... + 10)**2 = 55**2 = 3025 | ||
Hence the difference between the sum of the squares of the first ten natural | ||
numbers and the square of the sum is 3025 − 385 = 2640. | ||
Find the difference between the sum of the squares of the first one hundred | ||
natural numbers and the square of the sum. | ||
*/ | ||
package euler; | ||
|
||
public class p0006 implements IEuler { | ||
@Override | ||
public Object answer() { | ||
int sum_of_squares = 0, | ||
sum = 0; | ||
for (int i = 1; i < 101; i++) { | ||
sum += i; | ||
sum_of_squares += i * i; | ||
} | ||
|
||
int square_of_sum = sum * sum; | ||
return square_of_sum - sum_of_squares; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Project Euler Problem 9 | ||
Problem: | ||
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, | ||
a**2 + b**2 = c**2 | ||
For example, 3**2 + 4**2 = 9 + 16 = 25 = 5**2. | ||
There exists exactly one Pythagorean triplet for which a + b + c = 1000. | ||
Find the product abc. | ||
*/ | ||
package euler; | ||
|
||
public class p0009 implements IEuler { | ||
@Override | ||
public Object answer() { | ||
for (int c = 3; ; c++) { | ||
int c_square = c * c; | ||
for (int b = 2; b < c; b++) { | ||
int b_square = b * b; | ||
for (int a = 1; a < b; a++) { | ||
int a_square = a * a; | ||
if (a_square + b_square == c_square && a + b + c == 1000) | ||
return a * b * c; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.