-
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
22bc13e
commit 13fcf3c
Showing
6 changed files
with
60 additions
and
5 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 |
---|---|---|
|
@@ -155,4 +155,5 @@ Problems Solved | |
--------------- | ||
|
||
- ☒ `1 <./p0001.cpp>`__ | ||
- ☒ `2 <./p0002.cpp>`__ | ||
|
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,45 @@ | ||
/* | ||
Project Euler Problem 2 | ||
Again, see Python implementation for a proof | ||
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. | ||
*/ | ||
|
||
#ifndef EULER_P0002 | ||
#define EULER_P0002 | ||
#include <stdio.h> | ||
|
||
unsigned long long p0002() { | ||
unsigned long long answer = 0, | ||
a = 1, b = 2, t; | ||
while (b < 4000000) { | ||
// odd (1, 3, 13, 55, ...) | ||
// odd (1, 5, 21, 89, ...) | ||
// even (2, 8, 34, 144, ...) | ||
answer += b; | ||
for (unsigned char z = 0; z < 3; z++) { | ||
t = b; | ||
b = a + b; | ||
a = t; | ||
} | ||
} | ||
return answer; | ||
} | ||
|
||
#ifndef UNITY_END | ||
int main(int argc, char const *argv[]) { | ||
unsigned long long answer = p0002(); | ||
printf("%llu\n", answer); | ||
return 0; | ||
} | ||
#endif | ||
#endif |
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,8 @@ | ||
C++ Implementation of Problem 2 | ||
=============================== | ||
|
||
View source code `here on GitHub! <https://github.com/LivInTheLookingGlass/Euler/blob/master/cplusplus/p0002.cpp>`_ | ||
|
||
.. literalinclude:: ../../cplusplus/p0002.cpp | ||
:language: C++ | ||
: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