-
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
8a4f8c8
commit 45b1c54
Showing
13 changed files
with
119 additions
and
10 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,34 @@ | ||
/* | ||
Project Euler Problem 5 | ||
Problem: | ||
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. | ||
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? | ||
*/ | ||
using System; | ||
|
||
namespace Euler | ||
{ | ||
public class p0005 : IEuler | ||
{ | ||
public object Answer() | ||
{ | ||
int answer = 1; | ||
byte[] factorTracker = new byte[20], localFactorTracker = new byte[20]; | ||
for (byte i = 2; i < 21; i++) { | ||
foreach (byte p in Prime.PrimeFactors(i)) | ||
localFactorTracker[p]++; | ||
for (byte j = 2; j < 20; j++) { | ||
factorTracker[j] = Math.Max(factorTracker[j], localFactorTracker[j]); | ||
localFactorTracker[j] = 0; | ||
} | ||
} | ||
for (byte i = 2; i < 20; i++) | ||
for (byte j = 0; j < factorTracker[i]; j++) | ||
answer *= 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
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,18 @@ | ||
C# Implementation of Problem 5 | ||
============================== | ||
|
||
View source code :source:`csharp/Euler/p0005.cs` | ||
|
||
.. csharp:namespace:: Euler | ||
.. csharp:class:: p0005 | ||
.. csharp:inherits:: Euler.IEuler | ||
.. csharp:method:: object Answer() | ||
.. literalinclude:: ../../../csharp/Euler/p0005.cs | ||
:language: csharp | ||
:linenos: | ||
|
||
.. tags:: csharp-iterator, divisibility, factorization, prime-number |
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,24 @@ | ||
Java Implementation of Problem 5 | ||
================================ | ||
|
||
View source code :source:`java/src/main/java/euler/p0005.java` | ||
|
||
Includes | ||
-------- | ||
|
||
- `Primes.java <./lib/primes.html>`_ | ||
|
||
Problem Solution | ||
---------------- | ||
|
||
.. java:type:: public class p0005 implements IEuler | ||
.. java:method:: Object answer() | ||
:return: The answer to Project Euler problem 5 | ||
|
||
.. literalinclude:: ../../../java/src/main/java/euler/p0005.java | ||
:language: java | ||
:linenos: | ||
|
||
.. tags:: java-iterator, divisibility, factorization, prime-number |
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,33 @@ | ||
/* | ||
Project Euler Problem 5 | ||
Problem: | ||
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. | ||
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? | ||
*/ | ||
package euler; | ||
|
||
import euler.lib.Primes; | ||
|
||
public class p0005 implements IEuler { | ||
@Override | ||
public Object answer() { | ||
int answer = 1; | ||
int[] factorTracker = new int[20], localFactorTracker = new int[20]; | ||
for (int i = 2; i < 21; i++) { | ||
Primes.primeFactors(i) | ||
.mapToInt(Long::intValue) | ||
.forEach(p -> localFactorTracker[p]++); | ||
for (int j = 2; j < 20; j++) { | ||
factorTracker[j] = Math.max(factorTracker[j], localFactorTracker[j]); | ||
localFactorTracker[j] = 0; | ||
} | ||
} | ||
for (int i = 2; i < 20; i++) | ||
for (int j = 0; j < factorTracker[i]; j++) | ||
answer *= 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