-
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.
Port Javascript solution to rust, c#
- Loading branch information
1 parent
cac466f
commit e5ab1d8
Showing
14 changed files
with
148 additions
and
46 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,4 @@ | ||
Olivia Appleton <[email protected]> Gabe Appleton <[email protected]> | ||
Olivia Appleton <[email protected]> Gabe Appleton <[email protected]> | ||
Olivia Appleton <[email protected]> Olivia Appleton <[email protected]> | ||
Olivia Appleton <[email protected]> Olivia Appleton <[email protected]> |
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,39 @@ | ||
/* | ||
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. | ||
*/ | ||
using System; | ||
|
||
namespace Euler | ||
{ | ||
public class p0002 : IEuler | ||
{ | ||
public Task<Int64> Answer() | ||
{ | ||
Int64 answer = 0, | ||
i = 2, | ||
j = 8, | ||
tmp = 0; | ||
while (i < 4000000) | ||
{ | ||
answer += i; | ||
tmp = 4 * j + i; | ||
i = j; | ||
j = tmp; | ||
} | ||
return Task.FromResult<Int64>(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
C# Implementation of Problem 2 | ||
============================== | ||
|
||
View source code `here on GitHub! <https://github.com/LivInTheLookingGlass/Euler/blob/master/csharp/Euler/p0002.cs>`_ | ||
|
||
.. csharp:namespace:: Euler | ||
.. csharp:class:: p0002 | ||
.. csharp:inherits:: Euler.IEuler | ||
.. csharp:method:: Task<Int64> Answer() | ||
.. literalinclude:: ../../csharp/Euler/p0002.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Rust Implementation of Problem 2 | ||
================================ | ||
|
||
View source code `here on GitHub! <https://github.com/LivInTheLookingGlass/Euler/blob/master/rust/src/p0002.rs>`_ | ||
|
||
.. rust:function:: rust::p0002::p0002 | ||
.. literalinclude:: ../../rust/src/p0002.rs | ||
:language: rust | ||
: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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
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. | ||
*/ | ||
pub fn p0002() -> u64 { | ||
let mut answer = 0; | ||
let mut i = 2; | ||
let mut j = 8; | ||
let mut tmp = 0; | ||
while i < 4000000 { | ||
answer += i; | ||
tmp = 4 * j + i; | ||
i = j; | ||
j = tmp; | ||
} | ||
return answer; | ||
} |