Skip to content

Commit

Permalink
solve p6, p9 in lua
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Sep 7, 2024
1 parent aef147f commit 77a5cf7
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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| |
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`|
+-----------+-----------+------------+------------+------------+------------+------------+------------+------------+
Expand Down
18 changes: 18 additions & 0 deletions docs/src/lua/p0006.rst
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions docs/src/lua/p0009.rst
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions lua/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ Problems Solved

- ☒ `1 <./src/p0001.lua>`__
- ☒ `2 <./src/p0002.lua>`__
- ☒ `6 <./src/p0006.lua>`__
- ☒ `9 <./src/p0009.lua>`__
13 changes: 13 additions & 0 deletions lua/src/p0006.lua
Original file line number Diff line number Diff line change
@@ -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
}

22 changes: 22 additions & 0 deletions lua/src/p0009.lua
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions lua/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 77a5cf7

Please sign in to comment.