Skip to content

Commit

Permalink
Solve p19 in js
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 16, 2024
1 parent 516b47d commit 090899e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Olivia's Project Euler Solutions
| | Microsoft, Oracle, |br| | | |CodeQL| |br| |
| | Semeru, Temurin, & Zulu | | |Java-lint| |
+------------+----------------------------+--------+-------------------+
| JavaScript | Node 12+ |br| | 25 | |JavaScript| |br| |
| JavaScript | Node 12+ |br| | 26 | |JavaScript| |br| |
| | Bun 1.0+ |br| | | |Js-Cov| |br| |
| | Browser [#]_ | | |CodeQL| |br| |
| | | | |ESLint| |
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Problems Solved
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`18` | | | | | |:py-d:`0018`|:rs-d:`0018`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`19` | | | | | |:py-d:`0019`|:rs-d:`0019`|
|:prob:`19` | | | | |:js-d:`0019`|:py-d:`0019`|:rs-d:`0019`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`20` |:c-d:`0020` |:cp-d:`0020`|:cs-d:`0020`|:ja-d:`0020`|:js-d:`0020`|:py-d:`0020`|:rs-d:`0020`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
Expand Down
12 changes: 12 additions & 0 deletions docs/src/javascript/p0019.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
JavaScript Implementation of Problem 19
=======================================

View source code :source:`javascript/src/p0019.js`

.. js:autofunction:: p0019

.. literalinclude:: ../../../javascript/src/p0019.js
:language: javascript
:linenos:

.. tags:: calendar, combinatorics
36 changes: 36 additions & 0 deletions javascript/src/p0019.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Project Euler Problem 19
*
* This one ended up being very easy thanks to the Date object
*
* 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)?
*
* @return {number}
*/
exports.p0019 = function() {
let answer = 0;
for (let x = 1901; x < 2001; x += 1) {
for (let y = 1; y < 13; y += 1) {
if (new Date(x, y, 1).getDay() == 0) {
answer += 1;
}
}
}
return answer;
};

0 comments on commit 090899e

Please sign in to comment.