Skip to content

Commit

Permalink
Solve p10 in lua
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Sep 17, 2024
1 parent cbfdbf3 commit 07e70fb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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| |
+------------+----------------------------+--------+-------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`|
+-----------+-----------+------------+------------+------------+------------+------------+------------+------------+
Expand Down
23 changes: 23 additions & 0 deletions docs/src/lua/p0010.rst
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lua/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`__
Expand Down
24 changes: 24 additions & 0 deletions lua/src/p0010.lua
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions lua/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 07e70fb

Please sign in to comment.