-
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 p25, p30 from dev (which is now mostly not needed)
- Loading branch information
1 parent
6e6b391
commit 2fb14eb
Showing
13 changed files
with
220 additions
and
25 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
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,54 @@ | ||
/* | ||
Project Euler Problem 25 | ||
Problem: | ||
The Fibonacci sequence is defined by the recurrence relation: | ||
Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. | ||
Hence the first 12 terms will be: | ||
F1 = 1 | ||
F2 = 1 | ||
F3 = 2 | ||
F4 = 3 | ||
F5 = 5 | ||
F6 = 8 | ||
F7 = 13 | ||
F8 = 21 | ||
F9 = 34 | ||
F10 = 55 | ||
F11 = 89 | ||
F12 = 144 | ||
The 12th term, F12, is the first term to contain three digits. | ||
What is the index of the first term in the Fibonacci sequence to contain 1000 digits? | ||
*/ | ||
#ifndef EULER_P0025 | ||
#define EULER_P0025 | ||
#include <stdio.h> | ||
#include "include/bcd.h" | ||
|
||
unsigned long long p0025() { | ||
unsigned long long answer = 2; | ||
BCD_int a = BCD_one, b = BCD_one; | ||
while (b.decimal_digits < 1000) { | ||
iadd_bcd(&a, b); | ||
swap(a, b, BCD_int); | ||
answer++; | ||
} | ||
free_BCD_int(a); | ||
free_BCD_int(b); | ||
return answer; | ||
} | ||
|
||
#ifndef UNITY_END | ||
int main(int argc, char const *argv[]) { | ||
unsigned long long answer = p0025(); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Project Euler Problem 30 | ||
Problem: | ||
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: | ||
1634 = 1^4 + 6^4 + 3^4 + 4^4 | ||
8208 = 8^4 + 2^4 + 0^4 + 8^4 | ||
9474 = 9^4 + 4^4 + 7^4 + 4^4 | ||
As 1 = 1^4 is not a sum it is not included. | ||
The sum of these numbers is 1634 + 8208 + 9474 = 19316. | ||
Find the sum of all the numbers that can be written as the sum of fifth powers of their digits. | ||
*/ | ||
#ifndef EULER_P0030 | ||
#define EULER_P0030 | ||
#include <stdio.h> | ||
#include "include/digits.h" | ||
|
||
unsigned long long p0030() { | ||
unsigned long long answer = 0, sum, tmp; | ||
for (unsigned long long i = 2; i < 1000000; i++) { | ||
digit_counter dc = digits(i); | ||
sum = 0; | ||
while (!dc.exhausted) { | ||
tmp = next(dc); | ||
sum += tmp * tmp * tmp * tmp * tmp; | ||
} | ||
if (sum == i) { | ||
answer += i; | ||
} | ||
free_iterator(dc); | ||
} | ||
return answer; | ||
} | ||
|
||
#ifndef UNITY_END | ||
int main(int argc, char const *argv[]) { | ||
unsigned long long answer = p0030(); | ||
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 |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
*range(1, 18), | ||
20, | ||
22, | ||
25, | ||
30, | ||
34, | ||
76, | ||
836, | ||
|
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,25 @@ | ||
C Implementation of Problem 25 | ||
============================== | ||
|
||
View source code :source:`c/src/p0025.c` | ||
|
||
Includes | ||
-------- | ||
|
||
- `bcd.h <./lib/bcd.html>`__ | ||
|
||
Solution | ||
-------- | ||
|
||
.. c:function:: unsigned long long p0025() | ||
.. c:function:: int main(int argc, char const *argv[]) | ||
.. note:: | ||
This function is only present in the Python test runner, or when compiling as a standalone program. | ||
It is not present when compiling for the Unity test runner. | ||
.. literalinclude:: ../../../c/src/p0025.c | ||
: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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
C Implementation of Problem 30 | ||
============================== | ||
|
||
View source code :source:`c/src/p0030.c` | ||
|
||
Includes | ||
-------- | ||
|
||
- `digits.h <./lib/digits.html>`__ | ||
|
||
Solution | ||
-------- | ||
|
||
.. c:function:: unsigned long long p0030() | ||
.. c:function:: int main(int argc, char const *argv[]) | ||
.. note:: | ||
This function is only present in the Python test runner, or when compiling as a standalone program. | ||
It is not present when compiling for the Unity test runner. | ||
.. literalinclude:: ../../../c/src/p0030.c | ||
:language: C | ||
:linenos: |