-
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
0c30fa4
commit e421f36
Showing
26 changed files
with
155 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
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. | ||
*/ | ||
using System; | ||
|
||
namespace Euler | ||
{ | ||
public class p0034 : IEuler | ||
{ | ||
public object Answer() | ||
{ | ||
int answer = 0; | ||
for (int x = 10; x < 100000; x += 1) | ||
{ | ||
string xs = x.ToString(); | ||
int sum = 0; | ||
for (byte i = 0; i < xs.Length; i += 1) | ||
{ | ||
sum += (int)Mathematics.Factorial((ulong)(xs[i] - '0')); | ||
} | ||
if (sum == x) | ||
{ | ||
answer += x; | ||
} | ||
} | ||
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 |
---|---|---|
|
@@ -9,7 +9,6 @@ Library Code | |
------------ | ||
|
||
.. toctree:: | ||
:glob: | ||
:numbered: | ||
:maxdepth: 1 | ||
|
||
|
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 |
---|---|---|
|
@@ -9,7 +9,6 @@ Library Code | |
------------ | ||
|
||
.. toctree:: | ||
:glob: | ||
:numbered: | ||
:maxdepth: 1 | ||
|
||
|
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,16 @@ | ||
math.cs | ||
======= | ||
|
||
View source code `here on GitHub! <https://github.com/LivInTheLookingGlass/Euler/blob/master/csharp/include/math.cs>`_ | ||
|
||
.. csharp:namespace:: Euler | ||
.. csharp:class:: Mathematics | ||
.. csharp:method:: static ulong Factorial(ulong n) | ||
.. csharp:method:: static ulong NChooseR(ulong n, ulong r) | ||
.. literalinclude:: ../../csharp/Euler/include/math.cs | ||
:language: csharp | ||
: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
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
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 |
---|---|---|
|
@@ -14,7 +14,6 @@ Library Code | |
------------ | ||
|
||
.. toctree:: | ||
:glob: | ||
:numbered: | ||
:maxdepth: 1 | ||
|
||
|
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 @@ | ||
JavaScript Implementation of Problem 34 | ||
======================================= | ||
|
||
View source code `here on GitHub! <https://github.com/LivInTheLookingGlass/Euler/blob/master/javascript/src/p0034.js>`_ | ||
|
||
Includes | ||
-------- | ||
|
||
- `math <./math.html>`_ | ||
|
||
Problem Solution | ||
---------------- | ||
|
||
.. js:autofunction:: p0034 | ||
|
||
.. literalinclude:: ../../javascript/src/p0034.js | ||
:language: javascript | ||
: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 |
---|---|---|
|
@@ -9,7 +9,6 @@ Library Code | |
------------ | ||
|
||
.. toctree:: | ||
:glob: | ||
:numbered: | ||
:maxdepth: 1 | ||
|
||
|
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 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. | ||
* | ||
* @return {number} | ||
*/ | ||
exports.p0034 = function() { | ||
let answer = 0; | ||
for (let x = 10; x < 100000; x += 1) { | ||
let xs = x.toString(); | ||
let sum = 0; | ||
for (let i = 0; i < xs.length; i += 1) { | ||
sum += Mathematics.factorial(parseInt(xs[i])); | ||
} | ||
if (sum == x) { | ||
answer += x; | ||
} | ||
} | ||
return answer; | ||
}; | ||
|
||
const Mathematics = require('./lib/math.js'); |