-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6dd7fb6
commit 9c636c4
Showing
14 changed files
with
460 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Lua | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'lua/**' | ||
- '!lua/README.rst' | ||
schedule: | ||
- cron: "0 0 1 * *" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- windows-latest | ||
- macos-latest | ||
- macos-13 | ||
version: | ||
- 5.4 | ||
- 5.3 | ||
- 5.2 | ||
- 5.1 | ||
- 4.0 | ||
- 3.2 | ||
- 3.1 | ||
- 3.0 | ||
- 2.5 | ||
- 2.4 | ||
- 2.2 | ||
- 2.1 | ||
- 1.1 | ||
- 1.0 | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- uses: leafo/gh-actions-lua@v10 | ||
with: | ||
luaVersion: ${{ matrix.version }} | ||
|
||
- run: make lu_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ sphinx-notfound-page | |
javasphinx-workaround | ||
sphinx-tags | ||
sphinx-mathjax-offline | ||
sphinxcontrib-luadomain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Euler Lua Implementation | ||
======================== | ||
|
||
.. include:: ../../lua/README.rst | ||
:start-line: 2 | ||
:end-before: Problems Solved | ||
|
||
.. Library Code | ||
.. ------------ | ||
.. .. toctree:: | ||
.. :glob: | ||
.. :maxdepth: 1 | ||
.. lua/lib/* | ||
Problems Solved | ||
--------------- | ||
|
||
.. toctree:: | ||
:glob: | ||
:maxdepth: 1 | ||
|
||
lua/p[0-9][0-9][0-9][0-9] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Lua Implementation of Problem 1 | ||
=============================== | ||
|
||
View source code :source:`lua/src/p0001.lua` | ||
|
||
Solution | ||
-------- | ||
|
||
.. lua:function:: solution() | ||
:return: The solution to problem 1 | ||
:rtype: number | ||
|
||
.. literalinclude:: ../../../lua/src/p0001.lua | ||
:language: Lua | ||
:linenos: | ||
|
||
.. tags:: divisibility |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Lua Implementation of Problem 2 | ||
=============================== | ||
|
||
View source code :source:`lua/src/p0002.lua` | ||
|
||
Solution | ||
-------- | ||
|
||
.. lua:function:: solution() | ||
:return: The solution to problem 2 | ||
:rtype: number | ||
|
||
.. literalinclude:: ../../../lua/src/p0002.lua | ||
:language: Lua | ||
:linenos: | ||
|
||
.. tags:: divisibility, fibonacci-number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
BLUE=\033[0;34m | ||
NC=\033[0m # No Color | ||
|
||
.PHONY: help | ||
help: | ||
@echo " $(BLUE)test$(NC) Run through all Lua tests in sequence." | ||
@echo " $(BLUE)test_auto$(NC) Run through all Lua tests (parallel execution not implemented)." | ||
@echo " $(BLUE)clean$(NC) Clean up any stray files." | ||
|
||
.PHONY: test | ||
test: ../LICENSE | ||
@lua test_euler.lua | ||
|
||
test_%: test | ||
|
||
.PHONY: clean | ||
clean: | ||
@echo "No files to clean." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Lua Section | ||
============ | ||
|
||
.. .. |Lua Check| image:: https://github.com/LivInTheLookingGlass/Euler/actions/workflows/rust.yml/badge.svg | ||
.. :target: https://github.com/LivInTheLookingGlass/Euler/actions/workflows/rust.yml | ||
.. |Lua Check| | ||
Organization | ||
------------ | ||
|
||
All files share a common prefix with their problem number. All shared | ||
functions are moved to files in the include subfolder | ||
|
||
Makefile | ||
-------- | ||
|
||
There are three main recipes in this Makefile | ||
|
||
test | ||
~~~~ | ||
|
||
Runs the test script | ||
|
||
test\_\* | ||
~~~~~~~~ | ||
|
||
In most subdirectories this would run tests in parallel, however this is not implemented for lua, and it will be redirected to ``test`` | ||
|
||
clean | ||
~~~~~ | ||
|
||
Cleans up any stray files from runtime | ||
|
||
Tests | ||
----- | ||
|
||
Generic Problems | ||
~~~~~~~~~~~~~~~~ | ||
|
||
For each problem it will check the answer against a known dictionary. If | ||
the problem is not in the "known slow" category (meaning that I generate | ||
the correct answer with a poor solution), it will run it as many times | ||
as the benchmark plugin wants. Otherwise it is run exactly once. | ||
|
||
A test fails if it gets the wrong answer or if it takes more than 1 | ||
minute. | ||
|
||
Dependencies | ||
------------ | ||
|
||
I try to keep the dependencies of this project as small as possible, | ||
except for test plugins. At the moment there are no dependencies for this section. | ||
|
||
Problems Solved | ||
--------------- | ||
|
||
- ☒ `1 <./src/p0001.lua>`__ | ||
- ☒ `2 <./src/p0002.lua>`__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
return { | ||
solution = function() | ||
answer = 0 | ||
|
||
for i = 3,1000,3 | ||
do | ||
answer = answer + i | ||
end | ||
|
||
for i = 5,1000,5 | ||
do | ||
answer = answer + i | ||
end | ||
|
||
for i = 15,1000,15 | ||
do | ||
answer = answer - i | ||
end | ||
|
||
return answer | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
return { | ||
solution = function() | ||
answer = 0 | ||
a = 1 | ||
b = 2 | ||
|
||
while b < 4000000 | ||
do | ||
answer += b | ||
|
||
for j = 0,3,1 | ||
do | ||
t = b | ||
b = a + b | ||
a = t | ||
end | ||
end | ||
|
||
return answer | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- Function to load a problem solution file | ||
local function load_problem(file_name) | ||
local func, err = loadfile(file_name) | ||
if not func then | ||
error("Failed to load file " .. file_name .. ": " .. err) | ||
end | ||
local chunk = func() | ||
if type(chunk) ~= "table" or not chunk.solution then | ||
error("File " .. file_name .. " must return a table with a 'solution' function") | ||
end | ||
return chunk.solution | ||
end | ||
|
||
-- Timing and result check function | ||
local function check_problem(problem_func, expected_answer, timeout_seconds, problem_name) | ||
local start_time = os.clock() | ||
local success, result = pcall(problem_func) | ||
local elapsed_time = os.clock() - start_time | ||
|
||
if not success then | ||
error("Error executing " .. problem_name .. ": " .. result) | ||
end | ||
|
||
if result ~= expected_answer then | ||
error("Problem " .. problem_name .. " returned " .. tostring(result) .. ", but expected " .. tostring(expected_answer)) | ||
end | ||
|
||
if elapsed_time > timeout_seconds then | ||
error("Problem " .. problem_name .. " took " .. elapsed_time .. " seconds, exceeding the expected time limit of " .. timeout_seconds .. " seconds.") | ||
end | ||
|
||
print("Problem " .. problem_name .. " passed.") | ||
end | ||
|
||
-- Problems configuration: filename -> {expected_answer, timeout_seconds} | ||
local problems = { | ||
["p0001.lua"] = {233168, 60}, | ||
["p0002.lua"] = {4613732, 60}, | ||
-- Add more problems here as needed | ||
} | ||
|
||
-- Main testing loop | ||
for file_name, config in pairs(problems) do | ||
local problem_func = load_problem(file_name) | ||
check_problem(problem_func, config[1], config[2], file_name:match("(%d+)")) | ||
end |