Skip to content

Commit

Permalink
Solve p19 in lua
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Oct 15, 2024
1 parent 7addbda commit 0b679b8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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| |
+------------+----------------------------+--------+-------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`|
+-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+
Expand Down
14 changes: 14 additions & 0 deletions docs/src/fortran/p0019.rst
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lua/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`__
Expand Down
39 changes: 39 additions & 0 deletions lua/src/p0019.lua
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions lua/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 0b679b8

Please sign in to comment.