From 77a5cf7263e1987c6eaec8d3a95080bb60b882e1 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Fri, 6 Sep 2024 22:06:22 -0500 Subject: [PATCH] solve p6, p9 in lua --- README.rst | 2 +- docs/index.rst | 4 ++-- docs/src/lua/p0006.rst | 18 ++++++++++++++++++ docs/src/lua/p0009.rst | 18 ++++++++++++++++++ lua/README.rst | 2 ++ lua/src/p0006.lua | 13 +++++++++++++ lua/src/p0009.lua | 22 ++++++++++++++++++++++ lua/test.lua | 2 ++ 8 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 docs/src/lua/p0006.rst create mode 100644 docs/src/lua/p0009.rst create mode 100644 lua/src/p0006.lua create mode 100644 lua/src/p0009.lua diff --git a/README.rst b/README.rst index 08b3a24e..61a25a32 100644 --- a/README.rst +++ b/README.rst @@ -91,7 +91,7 @@ Olivia's Project Euler Solutions | | Browser [#]_ | | |CodeQL| |br| | | | | | |ESLint| | +------------+----------------------------+--------+-------------------+ - | Lua | Lua 5+ | 2 | |Luai| | + | Lua | Lua 5+ | 4 | |Luai| | +------------+----------------------------+--------+-------------------+ | Python | CPython 3.6+ |br| | 80 | |Python| |br| | | | Pypy 3.6+ |br| | | |Py-Cov| |br| | diff --git a/docs/index.rst b/docs/index.rst index 52d0d6bb..40565c0c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -87,13 +87,13 @@ Problems Solved +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`005`|:c-d:`0005`| | | |:js-d:`0005`| |:py-d:`0005`|:rs-d:`0005`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`006`|:c-d:`0006`|:cp-d:`0006`|:cs-d:`0006`|:ja-d:`0006`|:js-d:`0006`| |:py-d:`0006`|:rs-d:`0006`| + |:prob:`006`|:c-d:`0006`|:cp-d:`0006`|:cs-d:`0006`|:ja-d:`0006`|:js-d:`0006`|:lu-d:`0006`|:py-d:`0006`|:rs-d:`0006`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`007`|:c-d:`0007`|:cp-d:`0007`|:cs-d:`0007`| |:js-d:`0007`| |:py-d:`0007`|:rs-d:`0007`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`008`|:c-d:`0008`|:cp-d:`0008`|:cs-d:`0008`|:ja-d:`0008`|:js-d:`0008`| |:py-d:`0008`|:rs-d:`0008`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`009`|:c-d:`0009`|:cp-d:`0009`|:cs-d:`0009`|:ja-d:`0009`|:js-d:`0009`| |:py-d:`0009`|:rs-d:`0009`| + |:prob:`009`|:c-d:`0009`|:cp-d:`0009`|:cs-d:`0009`|:ja-d:`0009`|:js-d:`0009`|:lu-d:`0009`|:py-d:`0009`|:rs-d:`0009`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`010`|:c-d:`0010`| |:cs-d:`0010`| |:js-d:`0010`| |:py-d:`0010`|:rs-d:`0010`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ diff --git a/docs/src/lua/p0006.rst b/docs/src/lua/p0006.rst new file mode 100644 index 00000000..62000660 --- /dev/null +++ b/docs/src/lua/p0006.rst @@ -0,0 +1,18 @@ +Lua Implementation of Problem 6 +=============================== + +View source code :source:`lua/src/p0006.lua` + +Solution +-------- + +.. lua:function:: solution() + + :return: The solution to problem 6 + :rtype: number + +.. literalinclude:: ../../../lua/src/p0006.lua + :language: Lua + :linenos: + +.. tags:: divisibility diff --git a/docs/src/lua/p0009.rst b/docs/src/lua/p0009.rst new file mode 100644 index 00000000..2f527243 --- /dev/null +++ b/docs/src/lua/p0009.rst @@ -0,0 +1,18 @@ +Lua Implementation of Problem 9 +=============================== + +View source code :source:`lua/src/p0009.lua` + +Solution +-------- + +.. lua:function:: solution() + + :return: The solution to problem 9 + :rtype: number + +.. literalinclude:: ../../../lua/src/p0009.lua + :language: Lua + :linenos: + +.. tags:: divisibility diff --git a/lua/README.rst b/lua/README.rst index 904d175a..6b8370cb 100644 --- a/lua/README.rst +++ b/lua/README.rst @@ -57,3 +57,5 @@ Problems Solved - ☒ `1 <./src/p0001.lua>`__ - ☒ `2 <./src/p0002.lua>`__ +- ☒ `6 <./src/p0006.lua>`__ +- ☒ `9 <./src/p0009.lua>`__ diff --git a/lua/src/p0006.lua b/lua/src/p0006.lua new file mode 100644 index 00000000..7dc4ed89 --- /dev/null +++ b/lua/src/p0006.lua @@ -0,0 +1,13 @@ +return { + solution = function() + sum = 1 + sum_of_squares = 1 + for i = 2,100,1 + do + sum = sum + i + sum_of_squares = sum_of_squares + (i * i) + end + return (sum * sum) - sum_of_squares; + end +} + diff --git a/lua/src/p0009.lua b/lua/src/p0009.lua new file mode 100644 index 00000000..399fae7c --- /dev/null +++ b/lua/src/p0009.lua @@ -0,0 +1,22 @@ +return { + solution = function() + c = 3 + while true + do + c_square = c * c + for b = 2,c,1 + do + b_square = b * b + for a = 1,b,1 + do + a_square = a * a + if a_square + b_square == c_square and a + b + c == 1000 + then + return a * b * c + end + end + end + c = c + 1 + end + end +} diff --git a/lua/test.lua b/lua/test.lua index 5b61e354..a41917ad 100644 --- a/lua/test.lua +++ b/lua/test.lua @@ -36,6 +36,8 @@ end local problems = { ["p0001.lua"] = {233168, 60}, ["p0002.lua"] = {4613732, 60}, + ["p0006.lua"] = {25164150, 60}, + ["p0009.lua"] = {31875000, 60}, } -- Main testing loop