From 9c636c4a58702468cbfdc46c07edc02a024a63c9 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Thu, 5 Sep 2024 23:47:48 -0500 Subject: [PATCH] Add initial lua solutions --- .github/workflows/lua.yml | 50 ++++++ Makefile | 9 +- README.rst | 2 + docs/conf.py | 3 +- docs/index.rst | 346 +++++++++++++++++++------------------- docs/requirements.txt | 1 + docs/src/lua.rst | 24 +++ docs/src/lua/p0001.rst | 17 ++ docs/src/lua/p0002.rst | 17 ++ lua/Makefile | 18 ++ lua/README.rst | 59 +++++++ lua/src/p0001.lua | 22 +++ lua/src/p0002.lua | 21 +++ lua/test.lua | 46 +++++ 14 files changed, 460 insertions(+), 175 deletions(-) create mode 100644 .github/workflows/lua.yml create mode 100644 docs/src/lua.rst create mode 100644 docs/src/lua/p0001.rst create mode 100644 docs/src/lua/p0002.rst create mode 100644 lua/Makefile create mode 100644 lua/README.rst create mode 100644 lua/src/p0001.lua create mode 100644 lua/src/p0002.lua create mode 100644 lua/test.lua diff --git a/.github/workflows/lua.yml b/.github/workflows/lua.yml new file mode 100644 index 00000000..e681b379 --- /dev/null +++ b/.github/workflows/lua.yml @@ -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 diff --git a/Makefile b/Makefile index 2d415088..32deb849 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,9 @@ help: LICENSE @echo "The following jobs are available under the js_ prefix" @$(MAKE) js_help $(MFLAGS) --no-print-directory @echo + @echo "The following jobs are available under the lu_ prefix" + @$(MAKE) lu_help $(MFLAGS) --no-print-directory + @echo @echo "The following jobs are available under the py_ prefix" @$(MAKE) py_help $(MFLAGS) --no-print-directory @echo @@ -69,6 +72,10 @@ ja_%: LICENSE js_%: LICENSE @$(MAKE) -C javascript $* $(MFLAGS) --no-print-directory +.PHONY: lu_% +lu_%: LICENSE + @$(MAKE) -C lua $* $(MFLAGS) --no-print-directory + .PHONY: py_% py_%: LICENSE @$(MAKE) -C python $* $(MFLAGS) --no-print-directory @@ -78,4 +85,4 @@ rs_%: LICENSE @$(MAKE) -C rust $* $(MFLAGS) --no-print-directory %: - @$(MAKE) c_$* cp_$* cs_$* ja_$* js_$* py_$* rs_$* $(MFLAGS) --no-print-directory + @$(MAKE) c_$* cp_$* cs_$* ja_$* js_$* lu_$* py_$* rs_$* $(MFLAGS) --no-print-directory diff --git a/README.rst b/README.rst index af4c1b47..b60a4f66 100644 --- a/README.rst +++ b/README.rst @@ -89,6 +89,8 @@ Olivia's Project Euler Solutions | | Browser [#]_ | | |CodeQL| |br| | | | | | |ESLint| | +------------+----------------------------+--------+-------------------+ + | Lua | (In Progress) | 2 | (In Progress) | + +------------+----------------------------+--------+-------------------+ | Python | CPython 3.6+ |br| | 80 | |Python| |br| | | | Pypy 3.6+ |br| | | |Py-Cov| |br| | | | GraalPy 23.1+ |br| | | |CodeQL| |br| | diff --git a/docs/conf.py b/docs/conf.py index 6ea7076a..cf694628 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,6 +50,7 @@ # 'sphinx-computron', # 'sphinx-compendia', # 'sphinx-navtree', + 'sphinxcontrib-luadomain', ] try: @@ -121,7 +122,7 @@ # ('ju', 'julia'), # ('kt', 'kotlin'), # ('ls', 'lisp'), # sphinxcontrib-cldomain - # ('lu', 'lua'), # sphinx-lua or sphinxcontrib-luadomain + ('lu', 'lua'), # sphinx-lua or sphinxcontrib-luadomain # ('ma', 'matlab'), # sphinxcontrib-matlabdomain # ('mk', 'makefile'), # hacked together with sphinxcontrib-domaintools # ('oc', 'ocaml'), # sphinxcontrib-ocaml diff --git a/docs/index.rst b/docs/index.rst index a5a0a6e7..f9fa74eb 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -63,179 +63,179 @@ Problems Solved .. table:: :class: datatable centertable - +-----------+------------+------------+------------+------------+------------+------------+------------+ - | | |C| | |Cp| | |C#| | |Ja| | |Js| | |Py| | |Rs| | - +===========+============+============+============+============+============+============+============+ - | Coverage | |d| | |d| | |d| | |d| | |d| | |d| | |d| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - | Docs | |d| | |d| | |d| | |d| | |d| | |d| | |d| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - | Linting | |d| | |d| | |d| | |d| | |d| | |d| | |d| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - | Testing | |d| | |d| | |d| | |d| | |d| | |d| | |d| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - | Browser | |ip| | |ip| | | | |d| | |d| | |d| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`001`|:c-d:`0001` |:cp-d:`0001`|:cs-d:`0001`|:ja-d:`0001`|:js-d:`0001`|:py-d:`0001`|:rs-d:`0001`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`002`|:c-d:`0002` |:cp-d:`0002`|:cs-d:`0002`|:ja-d:`0002`|:js-d:`0002`|:py-d:`0002`|:rs-d:`0002`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`003`|:c-d:`0003` |:cp-d:`0003`|:cs-d:`0003`| |:js-d:`0003`|:py-d:`0003`|:rs-d:`0003`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`004`|:c-d:`0004` |:cp-d:`0004`|:cs-d:`0004`|:ja-d:`0004`|:js-d:`0004`|:py-d:`0004`|:rs-d:`0004`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |: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:`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:`010`|:c-d:`0010` | |:cs-d:`0010`| |:js-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`|:py-d:`0011`|:rs-d:`0011`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`012`|:c-s:`0012` | | | |:js-d:`0012`|:py-d:`0012`|:rs-d:`0012`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`013`|:c-d:`0013` |:cp-d:`0013`|:cs-d:`0013`|:ja-d:`0013`|:js-d:`0013`|:py-d:`0013`|:rs-d:`0013`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`014`|:c-d:`0014` |:cp-d:`0014`|:cs-d:`0014`|:ja-d:`0014`|:js-d:`0014`|:py-d:`0014`|:rs-d:`0014`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`015`|:c-d:`0015` |:cp-d:`0015`|:cs-d:`0015`|:ja-d:`0015`|:js-d:`0015`|:py-d:`0015`|:rs-d:`0015`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`016`|:c-d:`0016` |:cp-d:`0016`|:cs-d:`0016`|:ja-d:`0016`|:js-d:`0016`|:py-d:`0016`|:rs-d:`0016`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`017`|:c-d:`0017` |:cp-d:`0017`|:cs-d:`0017`|:ja-d:`0017`|:js-d:`0017`|:py-d:`0017`|:rs-d:`0017`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`018`| | | | |:js-d:`0018`|:py-d:`0018`|:rs-d:`0018`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`019`|:c-d:`0019` |:cp-d:`0019`|:cs-d:`0019`|:ja-d:`0019`|:js-d:`0019`|:py-d:`0019`|:rs-d:`0019`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`020`|:c-d:`0020` |:cp-d:`0020`|:cs-d:`0020`|:ja-d:`0020`|:js-d:`0020`|:py-d:`0020`|:rs-d:`0020`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`021`| | | | |:js-d:`0021`|:py-d:`0021`|:rs-i:`0021`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`022`|:c-d:`0022` |:cp-d:`0022`|:cs-d:`0022`|:ja-d:`0022`|:js-d:`0022`|:py-d:`0022`|:rs-d:`0022`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`023`| | | | |:js-d:`0023`|:py-d:`0023`|:rs-d:`0023`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`024`| | | | | |:py-d:`0024`|:rs-d:`0024`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`025`|:c-d:`0025` | | | | |:py-d:`0025`|:rs-d:`0025`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`027`| | | | |:js-d:`0027`|:py-d:`0027`|:rs-s:`0027`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`028`| | | | | |:py-d:`0028`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`029`| | | | | |:py-d:`0029`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`030`|:c-d:`0030` | | | | |:py-d:`0030`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`031`| | | | | |:py-d:`0031`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`032`| | | | | |:py-d:`0032`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`033`| | | | | |:py-d:`0033`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`034`|:c-d:`0034` |:cp-d:`0034`|:cs-d:`0034`|:ja-d:`0034`|:js-d:`0034`|:py-d:`0034`|:rs-d:`0034`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`035`| | | | |:js-d:`0035`|:py-d:`0035`|:rs-s:`0035`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`036`| | | | | |:py-d:`0036`|:rs-d:`0036`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`037`| | | | |:js-d:`0037`|:py-d:`0037`|:rs-s:`0037`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`038`| | | | | |:py-d:`0038`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`039`| | | | | |:py-d:`0039`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`040`| | | | | |:py-d:`0040`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`041`| | | | |:js-d:`0041`|:py-d:`0041`|:rs-d:`0041`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`042`| | | | | |:py-d:`0042`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`043`| | | | | |:py-d:`0043`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`044`| | | | | |:py-d:`0044`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`045`| | | | | |:py-d:`0045`|:rs-d:`0045`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`046`| | | | |:js-d:`0046`|:py-d:`0046`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`047`| | | | | |:py-d:`0047`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`048`| | | | | |:py-d:`0048`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`049`| | | | | |:py-d:`0049`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`050`| | | | | |:py-d:`0050`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`052`| | | | | |:py-d:`0052`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`053`| | | | | |:py-d:`0053`|:rs-d:`0053`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`055`| | | | | |:py-d:`0055`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`056`| | | | | |:py-d:`0056`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`057`| | | | | |:py-d:`0057`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`058`| | | | | |:py-d:`0058`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`059`| | | | | |:py-d:`0059`|:rs-d:`0059`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`060`| | | | |:js-d:`0060`|:py-d:`0060`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`063`| | | | | |:py-d:`0063`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`067`| | | | |:js-d:`0067`|:py-d:`0067`|:rs-d:`0067`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`069`| | | | | |:py-d:`0069`|:rs-d:`0069`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`070`| | | | | |:py-d:`0070`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`071`| | | | | |:py-d:`0071`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`073`| | | | | |:py-d:`0073`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`074`| | | | | |:py-d:`0074`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`076`|:c-d:`0076` |:cp-d:`0076`|:cs-s:`0076`|:ja-d:`0076`|:js-s:`0076`|:py-d:`0076`|:rs-s:`0076`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`077`| | | | | |:py-d:`0077`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`081`| | | | | |:py-d:`0081`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`087`| | | | | |:py-d:`0087`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`089`| | | | | |:py-d:`0089`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`092`| | | | | |:py-d:`0092`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`097`| | | | | |:py-d:`0097`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`099`| | | | | |:py-d:`0099`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`118`| | | | | |:py-s:`0118`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`123`| | | | | |:py-d:`0123`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`134`| | | | | |:py-d:`0134`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`145`| | | | | |:py-d:`0145`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`187`| | | | | |:py-d:`0187`|:rs-d:`0187`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`206`| | | | | |:py-d:`0206`| | - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`357`| | | | | |:py-s:`0357`|:rs-i:`0357`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`836`|:c-d:`0836` |:cp-d:`0836`|:cs-d:`0836`|:ja-d:`0836`|:js-d:`0836`|:py-d:`0836`|:rs-d:`0836`| - +-----------+------------+------------+------------+------------+------------+------------+------------+ + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + | | |C| | |Cp| | |C#| | |Ja| | |Js| | |Lu| | |Py| | |Rs| | + +===========+===========+============+============+============+============+============+============+============+ + | Coverage | |d| | |d| | |d| | |d| | |d| | | |d| | |d| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + | Docs | |d| | |d| | |d| | |d| | |d| | |d| | |d| | |d| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + | Linting | |d| | |d| | |d| | |d| | |d| | | |d| | |d| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + | Testing | |d| | |d| | |d| | |d| | |d| | |d| | |d| | |d| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + | Browser | |ip| | |ip| | | | |d| | | |d| | |d| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`001`|:c-d:`0001`|:cp-d:`0001`|:cs-d:`0001`|:ja-d:`0001`|:js-d:`0001`|:lu-d:`0001`|:py-d:`0001`|:rs-d:`0001`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`002`|:c-d:`0002`|:cp-d:`0002`|:cs-d:`0002`|:ja-d:`0002`|:js-d:`0002`|:lu-d:`0002`|:py-d:`0002`|:rs-d:`0002`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`003`|:c-d:`0003`|:cp-d:`0003`|:cs-d:`0003`| |:js-d:`0003`| |:py-d:`0003`|:rs-d:`0003`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`004`|:c-d:`0004`|:cp-d:`0004`|:cs-d:`0004`|:ja-d:`0004`|:js-d:`0004`| |:py-d:`0004`|:rs-d:`0004`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |: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:`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:`010`|:c-d:`0010`| |:cs-d:`0010`| |:js-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`| |:py-d:`0011`|:rs-d:`0011`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`012`|:c-s:`0012`| | | |:js-d:`0012`| |:py-d:`0012`|:rs-d:`0012`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`013`|:c-d:`0013`|:cp-d:`0013`|:cs-d:`0013`|:ja-d:`0013`|:js-d:`0013`| |:py-d:`0013`|:rs-d:`0013`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`014`|:c-d:`0014`|:cp-d:`0014`|:cs-d:`0014`|:ja-d:`0014`|:js-d:`0014`| |:py-d:`0014`|:rs-d:`0014`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`015`|:c-d:`0015`|:cp-d:`0015`|:cs-d:`0015`|:ja-d:`0015`|:js-d:`0015`| |:py-d:`0015`|:rs-d:`0015`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`016`|:c-d:`0016`|:cp-d:`0016`|:cs-d:`0016`|:ja-d:`0016`|:js-d:`0016`| |:py-d:`0016`|:rs-d:`0016`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`017`|:c-d:`0017`|:cp-d:`0017`|:cs-d:`0017`|:ja-d:`0017`|:js-d:`0017`| |:py-d:`0017`|:rs-d:`0017`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`018`| | | | |:js-d:`0018`| |:py-d:`0018`|:rs-d:`0018`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`019`|:c-d:`0019`|:cp-d:`0019`|:cs-d:`0019`|:ja-d:`0019`|:js-d:`0019`| |:py-d:`0019`|:rs-d:`0019`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`020`|:c-d:`0020`|:cp-d:`0020`|:cs-d:`0020`|:ja-d:`0020`|:js-d:`0020`| |:py-d:`0020`|:rs-d:`0020`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`021`| | | | |:js-d:`0021`| |:py-d:`0021`|:rs-i:`0021`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`022`|:c-d:`0022`|:cp-d:`0022`|:cs-d:`0022`|:ja-d:`0022`|:js-d:`0022`| |:py-d:`0022`|:rs-d:`0022`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`023`| | | | |:js-d:`0023`| |:py-d:`0023`|:rs-d:`0023`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`024`| | | | | | |:py-d:`0024`|:rs-d:`0024`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`025`|:c-d:`0025`| | | | | |:py-d:`0025`|:rs-d:`0025`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`027`| | | | |:js-d:`0027`| |:py-d:`0027`|:rs-s:`0027`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`028`| | | | | | |:py-d:`0028`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`029`| | | | | | |:py-d:`0029`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`030`|:c-d:`0030`| | | | | |:py-d:`0030`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`031`| | | | | | |:py-d:`0031`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`032`| | | | | | |:py-d:`0032`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`033`| | | | | | |:py-d:`0033`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`034`|:c-d:`0034`|:cp-d:`0034`|:cs-d:`0034`|:ja-d:`0034`|:js-d:`0034`| |:py-d:`0034`|:rs-d:`0034`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`035`| | | | |:js-d:`0035`| |:py-d:`0035`|:rs-s:`0035`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`036`| | | | | | |:py-d:`0036`|:rs-d:`0036`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`037`| | | | |:js-d:`0037`| |:py-d:`0037`|:rs-s:`0037`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`038`| | | | | | |:py-d:`0038`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`039`| | | | | | |:py-d:`0039`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`040`| | | | | | |:py-d:`0040`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`041`| | | | |:js-d:`0041`| |:py-d:`0041`|:rs-d:`0041`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`042`| | | | | | |:py-d:`0042`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`043`| | | | | | |:py-d:`0043`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`044`| | | | | | |:py-d:`0044`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`045`| | | | | | |:py-d:`0045`|:rs-d:`0045`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`046`| | | | |:js-d:`0046`| |:py-d:`0046`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`047`| | | | | | |:py-d:`0047`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`048`| | | | | | |:py-d:`0048`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`049`| | | | | | |:py-d:`0049`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`050`| | | | | | |:py-d:`0050`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`052`| | | | | | |:py-d:`0052`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`053`| | | | | | |:py-d:`0053`|:rs-d:`0053`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`055`| | | | | | |:py-d:`0055`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`056`| | | | | | |:py-d:`0056`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`057`| | | | | | |:py-d:`0057`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`058`| | | | | | |:py-d:`0058`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`059`| | | | | | |:py-d:`0059`|:rs-d:`0059`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`060`| | | | |:js-d:`0060`| |:py-d:`0060`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`063`| | | | | | |:py-d:`0063`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`067`| | | | |:js-d:`0067`| |:py-d:`0067`|:rs-d:`0067`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`069`| | | | | | |:py-d:`0069`|:rs-d:`0069`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`070`| | | | | | |:py-d:`0070`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`071`| | | | | | |:py-d:`0071`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`073`| | | | | | |:py-d:`0073`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`074`| | | | | | |:py-d:`0074`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`076`|:c-d:`0076`|:cp-d:`0076`|:cs-s:`0076`|:ja-d:`0076`|:js-s:`0076`| |:py-d:`0076`|:rs-s:`0076`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`077`| | | | | | |:py-d:`0077`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`081`| | | | | | |:py-d:`0081`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`087`| | | | | | |:py-d:`0087`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`089`| | | | | | |:py-d:`0089`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`092`| | | | | | |:py-d:`0092`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`097`| | | | | | |:py-d:`0097`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`099`| | | | | | |:py-d:`0099`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`118`| | | | | | |:py-s:`0118`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`123`| | | | | | |:py-d:`0123`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`134`| | | | | | |:py-d:`0134`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`145`| | | | | | |:py-d:`0145`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`187`| | | | | | |:py-d:`0187`|:rs-d:`0187`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`206`| | | | | | |:py-d:`0206`| | + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`357`| | | | | | |:py-s:`0357`|:rs-i:`0357`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ + |:prob:`836`|:c-d:`0836`|:cp-d:`0836`|:cs-d:`0836`|:ja-d:`0836`|:js-d:`0836`| |:py-d:`0836`|:rs-d:`0836`| + +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+ .. toctree:: :glob: diff --git a/docs/requirements.txt b/docs/requirements.txt index 2e337957..9141f37b 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -11,3 +11,4 @@ sphinx-notfound-page javasphinx-workaround sphinx-tags sphinx-mathjax-offline +sphinxcontrib-luadomain diff --git a/docs/src/lua.rst b/docs/src/lua.rst new file mode 100644 index 00000000..a8e39a12 --- /dev/null +++ b/docs/src/lua.rst @@ -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] diff --git a/docs/src/lua/p0001.rst b/docs/src/lua/p0001.rst new file mode 100644 index 00000000..e97b8a1c --- /dev/null +++ b/docs/src/lua/p0001.rst @@ -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 diff --git a/docs/src/lua/p0002.rst b/docs/src/lua/p0002.rst new file mode 100644 index 00000000..f9b89915 --- /dev/null +++ b/docs/src/lua/p0002.rst @@ -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 diff --git a/lua/Makefile b/lua/Makefile new file mode 100644 index 00000000..0c0e51d6 --- /dev/null +++ b/lua/Makefile @@ -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." diff --git a/lua/README.rst b/lua/README.rst new file mode 100644 index 00000000..904d175a --- /dev/null +++ b/lua/README.rst @@ -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>`__ diff --git a/lua/src/p0001.lua b/lua/src/p0001.lua new file mode 100644 index 00000000..5a4d54fe --- /dev/null +++ b/lua/src/p0001.lua @@ -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 +} diff --git a/lua/src/p0002.lua b/lua/src/p0002.lua new file mode 100644 index 00000000..8ec47c34 --- /dev/null +++ b/lua/src/p0002.lua @@ -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 +} diff --git a/lua/test.lua b/lua/test.lua new file mode 100644 index 00000000..fc34a2b4 --- /dev/null +++ b/lua/test.lua @@ -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