diff --git a/README.rst b/README.rst index cbcc3a02..3c7f968e 100644 --- a/README.rst +++ b/README.rst @@ -46,7 +46,7 @@ Olivia's Project Euler Solutions +------------+--------------------------+--------+-------------------+ | Language | Version | Solved | Status | +============+==========================+========+===================+ -| C | C99+ in: |clang|, |br| | 20 | |Ci| |br| | +| C | C99+ in: |clang|, |br| | 21 | |Ci| |br| | | | |gcc|, |pcc|, |tcc| |br| | | |C-Cov| |br| | | | C11+ in: |msvc| [1]_ | | |CodeQL| | +------------+--------------------------+--------+-------------------+ diff --git a/c/README.rst b/c/README.rst index f3bbff8f..a1bf4c16 100644 --- a/c/README.rst +++ b/c/README.rst @@ -179,6 +179,7 @@ Problems Solved - ☒ `14 <./src/p0014.c>`__ - ☒ `15 <./src/p0015.c>`__ - ☒ `16 <./src/p0016.c>`__ +- ☒ `22 <./src/p0022.c>`__ - ☒ `34 <./src/p0034.c>`__ - ☒ `76 <./src/p0076.c>`__ - ☒ `836 <./src/p0836.c>`__ diff --git a/c/test.c b/c/test.c index e73de301..1baac7a7 100644 --- a/c/test.c +++ b/c/test.c @@ -17,6 +17,7 @@ #include "src/p0015.c" #include "src/p0016.c" #include "src/p0017.c" +#include "src/p0022.c" #include "src/p0034.c" #include "src/p0076.c" #include "src/p0836.c" @@ -44,6 +45,7 @@ const Answer answers[] = { {15, 137846528820, p0015}, {16, 1366, p0016}, {17, 21124, p0017}, + {22, 871198282, p0022}, {34, 40730, p0034}, {76, 190569291, (unsigned long long (*)()) p0076}, }; diff --git a/c/test_euler.py b/c/test_euler.py index 12dd8fed..2cf2c732 100644 --- a/c/test_euler.py +++ b/c/test_euler.py @@ -37,6 +37,7 @@ 15: 137846528820, 16: 1366, 17: 21124, + 22: 871198282, 34: 40730, 76: 190569291, 836: b"aprilfoolsjoke", diff --git a/docs/c/p0022.rst b/docs/c/p0022.rst new file mode 100644 index 00000000..3a304db0 --- /dev/null +++ b/docs/c/p0022.rst @@ -0,0 +1,29 @@ +C Implementation of Problem 22 +============================== + +View source code :source:`c/src/p0022.c` + +Includes +-------- + +- `utils.h <./utils.html>`__ + +Solution +-------- + +.. c:function:: int cmpstr(const void *a, const void *b) + + A wrapper around ``strcmp()`` to adapt it for ``qsort()`` + +.. c:function:: unsigned long long p0022() + +.. 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/p0022.c + :language: C + :linenos: diff --git a/docs/c/utils.rst b/docs/c/utils.rst new file mode 100644 index 00000000..cddd2267 --- /dev/null +++ b/docs/c/utils.rst @@ -0,0 +1,18 @@ +utils.h +======= + +View source code :source:`c/src/include/utils.h` + +.. c:namespace-push:: utils + +.. c:function:: char *get_data_file(const char *name) + + Return a character array containing thr whole contents of a file found in _data. + +.. c:function:: char *get_parent_directory(const char *name, const unsigned int levels) + +.. c:namespace-pop:: + +.. literalinclude:: ../../c/src/include/utils.h + :language: C + :linenos: diff --git a/docs/index.rst b/docs/index.rst index a020e909..fc18588a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -169,7 +169,7 @@ Problems Solved +-----------+------------+------------+------------+------------+------------+------------+ |:prob:`21` | | | | |:py-d:`0021`| | +-----------+------------+------------+------------+------------+------------+------------+ -|:prob:`22` | | | | |:py-d:`0022`|:rs-d:`0022`| +|:prob:`22` |:c-d:`0022` | | | |:py-d:`0022`|:rs-d:`0022`| +-----------+------------+------------+------------+------------+------------+------------+ |:prob:`23` | | | | |:py-d:`0023`| | +-----------+------------+------------+------------+------------+------------+------------+