diff --git a/README.rst b/README.rst index ba757f9f..c74a862b 100644 --- a/README.rst +++ b/README.rst @@ -95,7 +95,7 @@ Olivia's Project Euler Solutions | | Browser [#]_ | | |CodeQL| |br| | | | | | |ESLint| | +------------+----------------------------+--------+-------------------+ - | Lua | PUC-Rio Lua 5+ [#]_ | 18 | |Luai| |br| | + | Lua | PUC-Rio Lua 5+ [#]_ | 19 | |Luai| |br| | | | | | |Lu-Cov| |br| | | | | | |LuaCheck| | +------------+----------------------------+--------+-------------------+ diff --git a/docs/index.rst b/docs/index.rst index 798d93c5..0114ad92 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -95,7 +95,7 @@ Problems Solved +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ |: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`|:cp-d:`0010`|:cs-d:`0010`|:ja-d:`0010`|:js-d:`0010`| |:py-d:`0010`|:rs-d:`0010`| + |:prob:`010`|:c-d:`0010`|:cp-d:`0010`|:cs-d:`0010`|:ja-d:`0010`|:js-d:`0010`|:lu-d:`0010`|:py-d:`0010`|:rs-d:`0010`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`011`|:c-d:`0011`|:cp-d:`0011`|:cs-d:`0011`|:ja-d:`0011`|:js-d:`0011`|:lu-d:`0011`|:py-d:`0011`|:rs-d:`0011`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ diff --git a/docs/src/lua/p0010.rst b/docs/src/lua/p0010.rst new file mode 100644 index 00000000..773d6dd3 --- /dev/null +++ b/docs/src/lua/p0010.rst @@ -0,0 +1,23 @@ +Lua Implementation of Problem 10 +================================ + +View source code :source:`lua/src/p0010.lua` + +Includes +-------- + +- `primes.lua <./lib/primes.html>`__ + +Solution +-------- + +.. lua:function:: solution() + + :return: The solution to problem 10 + :rtype: number + +.. literalinclude:: ../../../lua/src/p0010.lua + :language: Lua + :linenos: + +.. tags:: prime-number, lua-iterator diff --git a/lua/README.rst b/lua/README.rst index 988ae3af..5eaedcf8 100644 --- a/lua/README.rst +++ b/lua/README.rst @@ -68,6 +68,7 @@ Problems Solved - ☒ `7 <./src/p0007.lua>`__ - ☒ `8 <./src/p0008.lua>`__ - ☒ `9 <./src/p0009.lua>`__ +- ☒ `10 <./src/p0010.lua>`__ - ☒ `11 <./src/p0011.lua>`__ - ☒ `13 <./src/p0013.lua>`__ - ☒ `14 <./src/p0014.lua>`__ diff --git a/lua/src/p0010.lua b/lua/src/p0010.lua new file mode 100644 index 00000000..f1b5b29d --- /dev/null +++ b/lua/src/p0010.lua @@ -0,0 +1,24 @@ +-- Project Euler Problem 10 +-- +-- Problem: +-- +-- The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. +-- +-- Find the sum of all the primes below two million. + +local primes = loadlib("primes").primes + +return { + solution = function() + local answer = 0 + local pg = primes(2000000) + local tmp = pg.next() + + repeat + answer = answer + tmp + tmp = pg.next() + until tmp == nil + + return answer; + end +} diff --git a/lua/test.lua b/lua/test.lua index bc4073f4..4e1d91bf 100644 --- a/lua/test.lua +++ b/lua/test.lua @@ -82,6 +82,7 @@ local problems = { ["p0007.lua"] = {104743, false}, ["p0008.lua"] = {23514624000, false}, ["p0009.lua"] = {31875000, false}, + ["p0010.lua"] = {142913828922, false}, ["p0011.lua"] = {70600674, false}, ["p0013.lua"] = {5537376230, false}, ["p0014.lua"] = {837799, false},