Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.7k
solution: Project Euler Problem 19#1174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
MatheusMuriel wants to merge6 commits intoTheAlgorithms:masterChoose a base branch fromMatheusMuriel:ProjectEuler019
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
/* | ||
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)? | ||
*/ | ||
export function countingSundays () { | ||
let numberOfSundays = 0 | ||
let dow = 2 | ||
// The number od days in each month of the year | ||
const months = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | ||
for (let y = 1901; y <= 2000; y++) { | ||
MatheusMuriel marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// Calculate the number of Days in February this year | ||
months[1] = 28 + ((y % 4 === 0 && y % 100 !== 0) || y % 400 === 0) | ||
for (const month of months) { | ||
dow = dow + (month % 7) | ||
if (dow % 7 === 0) { | ||
numberOfSundays++ | ||
} | ||
} | ||
} | ||
return numberOfSundays | ||
} |
This file contains hidden or 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,8 @@ | ||
import { countingSundays } from '../Problem019.js' | ||
describe('checking Counting Sundays', () => { | ||
// Project Euler Condition Check | ||
test('Test Euler Condition', () => { | ||
expect(countingSundays()).toBe(171) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.