diff --git a/README.rst b/README.rst index 486d7711..292d6139 100644 --- a/README.rst +++ b/README.rst @@ -103,7 +103,7 @@ Olivia's Project Euler Solutions | | Browser [#]_ | | |CodeQL| |br| | | | | | |ESLint| | +------------+----------------------------+--------+-------------------+ - | Lua | PUC-Rio Lua 5+ [#]_ | 22 | |Luai| |br| | + | Lua | PUC-Rio Lua 5+ [#]_ | 23 | |Luai| |br| | | | | | |Lu-Cov| |br| | | | | | |LuaCheck| | +------------+----------------------------+--------+-------------------+ diff --git a/docs/index.rst b/docs/index.rst index 37ab1b4b..1dcbcf83 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -114,7 +114,7 @@ Problems Solved +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+ |: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:`019`|:c-d:`0019`|:cp-d:`0019`|:cs-d:`0019`| |:ja-d:`0019`|:js-d:`0019`|:lu-d:`0019`|:py-d:`0019`|:rs-d:`0019`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`020`|:c-d:`0020`|:cp-d:`0020`|:cs-d:`0020`|:fr-d:`0020`|:ja-d:`0020`|:js-d:`0020`|:lu-d:`0020`|:py-d:`0020`|:rs-d:`0020`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+ diff --git a/docs/src/fortran/p0019.rst b/docs/src/fortran/p0019.rst new file mode 100644 index 00000000..88acc8fc --- /dev/null +++ b/docs/src/fortran/p0019.rst @@ -0,0 +1,14 @@ +Fortran Implementation of Problem 19 +==================================== + +View source code :source:`fortran/src/p0019.f90` + +.. f:module:: Problem0019 + +.. f:function:: integer Problem0019/p0019() + +.. literalinclude:: ../../../fortran/src/p0019.f90 + :language: Fortran + :linenos: + +.. tags:: calendar, combinatorics diff --git a/lua/README.rst b/lua/README.rst index ec49a9b5..1eaddbda 100644 --- a/lua/README.rst +++ b/lua/README.rst @@ -75,6 +75,7 @@ Problems Solved - ☒ `15 <./src/p0015.lua>`__ - ☒ `16 <./src/p0016.lua>`__ - ☒ `17 <./src/p0017.lua>`__ +- ☒ `19 <./src/p0019.lua>`__ - ☒ `20 <./src/p0020.lua>`__ - ☒ `22 <./src/p0022.lua>`__ - ☒ `28 <./src/p0028.lua>`__ diff --git a/lua/src/p0019.lua b/lua/src/p0019.lua new file mode 100644 index 00000000..511f9879 --- /dev/null +++ b/lua/src/p0019.lua @@ -0,0 +1,39 @@ +-- Project Euler Problem 19 +-- +-- This one ended up being very easy thanks to the time library +-- +-- Problem: +-- +-- You are given the following information, but you may prefer to do some research +-- for yourself. +-- +-- 1 Jan 1900 was a Monday. +-- Thirty days has September, +-- April, June and November. +-- All the rest have thirty-one, +-- Saving February alone, +-- Which has twenty-eight, rain or shine. +-- And on leap years, twenty-nine. +-- A leap year occurs on any year evenly divisible by 4, but not on a century +-- unless it is divisible by 400. +-- +-- How many Sundays fell on the first of the month during the twentieth century +-- (1 Jan 1901 to 31 Dec 2000)? + +local function is_sunday(year, month, day) + return os.date("*t", os.time({year=year, month=month, day=day})).wday == 1 +end + +return { + solution = function() + local answer = 0 + for year = 1901, 2000 do + for month = 1, 12 do + if is_sunday(year, month, 1) then + answer = answer + 1 + end + end + end + return answer + end +} diff --git a/lua/test.lua b/lua/test.lua index ccde5647..197662da 100644 --- a/lua/test.lua +++ b/lua/test.lua @@ -84,6 +84,8 @@ for i = 13, 17 do end local more_problems = { + ["p0019.lua"] = {get_answer(19), false}, + ["p0020.lua"] = {get_answer(20), false}, ["p0022.lua"] = {get_answer(22), false}, ["p0028.lua"] = {get_answer(28), false}, ["p0034.lua"] = {get_answer(34), false},