Created
November 21, 2011 05:59
-
-
Save jakedobkin/1381787 to your computer and use it in GitHub Desktop.
Euler 19
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
| #!/usr/local/bin/node | |
| // set up arrays for day names and number of days in month | |
| days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] | |
| daysinmonth = [31,28,31,30,31,30,31,31,30,31,30,31] | |
| daysinmonth_leapyear = [31,29,31,30,31,30,31,31,30,31,30,31] | |
| // enter starting day and date (monday = 1 in our array), also initials vars | |
| // 1.1.1901 is a tuesday (2 in days array)- i figured that out using this program | |
| // but using the info they gave us about 1/1/1900 being a monday. | |
| day = 2; | |
| date= 1; | |
| month = 1; | |
| year = 1901; | |
| count = 0; | |
| isleap = false; | |
| // while loop counts up until these are all true | |
| while ((date != 31 || month !=12 || year !=2000)) | |
| { | |
| day +=1; | |
| date +=1; | |
| if (date > daysinmonth[month-1] && isleap == false) | |
| { | |
| month +=1; | |
| date=1; | |
| } | |
| if (date > daysinmonth_leapyear[month-1] && isleap == true) | |
| { | |
| month +=1; | |
| date=1; | |
| } | |
| if (month > 12) | |
| { | |
| year +=1; | |
| month = 1; | |
| } | |
| if (year%4==0) | |
| { | |
| isleap = true; | |
| } | |
| else | |
| { | |
| isleap = false; | |
| } | |
| if (day%7 == 0 && date == 1) | |
| { | |
| count += 1; | |
| } | |
| // console.log ("today is " + month + "/" + date + "/" + year + " and it is a " + days[day%7]); | |
| } | |
| console.log("There are " + count + " dates where the first of the month is on a Sunday in this range"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment