-
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.
- Loading branch information
1 parent
b121fb9
commit 4d336bb
Showing
13 changed files
with
202 additions
and
8 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
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,14 @@ | ||
Java Implementation of Problem 20 | ||
================================= | ||
|
||
View source code :source:`java/src/main/java/euler/p0020.java` | ||
|
||
.. java:type:: public class p0020 implements IEuler | ||
.. java:method:: Object answer() | ||
:return: The answer to Project Euler problem 20 | ||
|
||
.. literalinclude:: ../../java/src/main/java/euler/p0020.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Java Implementation of Problem 34 | ||
================================= | ||
|
||
View source code :source:`java/src/main/java/euler/p0034.java` | ||
|
||
.. java:type:: public class p0034 implements IEuler | ||
.. java:method:: Object answer() | ||
:return: The answer to Project Euler problem 34 | ||
|
||
.. literalinclude:: ../../java/src/main/java/euler/p0034.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,14 @@ | ||
Java Implementation of Problem 76 | ||
================================= | ||
|
||
View source code :source:`java/src/main/java/euler/p0076.java` | ||
|
||
.. java:type:: public class p0076 implements IEuler | ||
.. java:method:: Object answer() | ||
:return: The answer to Project Euler problem 76 | ||
|
||
.. literalinclude:: ../../java/src/main/java/euler/p0076.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Project Euler Problem 34 | ||
This ended up being a filtering problem. The problem with my solution is that I | ||
am not satisfied with my filter at all. I feel like there is a more efficient | ||
way to go about it. | ||
Problem: | ||
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. | ||
Find the sum of all numbers which are equal to the sum of the factorial of | ||
their digits. | ||
Note: as 1! = 1 and 2! = 2 are not sums they are not included. | ||
*/ | ||
package euler; | ||
|
||
public class p0020 implements IEuler { | ||
@Override | ||
public Object answer() { | ||
long[] numbers = new long[10]; | ||
long ten17 = 100000000000000000L; | ||
numbers[0] = 1; | ||
for (byte i = 2; i <= 100; i++) { | ||
for (byte j = 0; j < 10; j++) { | ||
numbers[j] *= i; | ||
} | ||
for (byte j = 0; j < 9; j++) { | ||
if (numbers[j] > ten17) { | ||
numbers[j + 1] += numbers[j] / ten17; | ||
numbers[j] %= ten17; | ||
} | ||
} | ||
} | ||
long answer = 0; | ||
long power = 1; | ||
for (byte i = 0; i < 19; i++) { | ||
for (byte j = 0; j < 10; j++) { | ||
long value = numbers[j] / power; | ||
answer += value % 10; | ||
} | ||
power *= 10; | ||
} | ||
return (short) 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
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 34 | ||
This ended up being a filtering problem. The problem with my solution is that I | ||
am not satisfied with my filter at all. I feel like there is a more efficient | ||
way to go about it. | ||
Problem: | ||
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. | ||
Find the sum of all numbers which are equal to the sum of the factorial of | ||
their digits. | ||
Note: as 1! = 1 and 2! = 2 are not sums they are not included. | ||
*/ | ||
package euler; | ||
|
||
import euler.lib.Mathematics; | ||
|
||
public class p0034 implements IEuler { | ||
@Override | ||
public Object answer() { | ||
int answer = 0; | ||
for (int x = 10; x < 100000; x += 1) { | ||
String xs = Integer.toString(x); | ||
int sum = 0; | ||
for (byte i = 0; i < xs.length(); i += 1) | ||
sum += (int) Mathematics.factorial(xs.charAt(i) - '0'); | ||
if (sum == x) | ||
answer += x; | ||
} | ||
return (short) 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,50 @@ | ||
/* | ||
Project Euler Problem 76 | ||
I ended up having to do this iteratively, which I'm not super happy with. I feel like there is almost certainly a | ||
closed-form solution to this, but I was unable to figure it out. | ||
Problem: | ||
It is possible to write five as a sum in exactly six different ways: | ||
4 + 1 | ||
3 + 2 | ||
3 + 1 + 1 | ||
2 + 2 + 1 | ||
2 + 1 + 1 + 1 | ||
1 + 1 + 1 + 1 + 1 | ||
How many different ways can one hundred be written as a sum of at least two | ||
positive integers? | ||
*/ | ||
package euler; | ||
|
||
public class p0076 implements IEuler { | ||
@Override | ||
public Object answer() { | ||
byte idx, sum = 100; | ||
int answer = 0; | ||
byte[] counts = new byte[101]; | ||
counts[2] = 100; | ||
while (counts[100] == 0) { | ||
counts[2] += 2; | ||
if (sum >= 100) { | ||
answer += (100 + counts[2] - sum) / 2; | ||
idx = 2; | ||
do { | ||
counts[idx] = 0; | ||
idx += 1; | ||
counts[idx] += idx; | ||
sum = 0; | ||
for (byte i = (byte) (idx - 1); i < 101; i += 1) | ||
sum += counts[i]; | ||
} while (sum > 100); | ||
} | ||
sum = 0; | ||
for (byte i = 0; i < 101; i += 1) | ||
sum += counts[i]; | ||
} | ||
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