Problem Statement
Given an interval from one month to another, you are to determine how many blue moons there are between those two months, inclusive. To solve this you must know the following:
- Every year has 12 months.
- In a normal year, the number of days in each month are, in order starting with January, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
- In leap years, the second month (February) has 29 days instead of 28.
- Leap years occur every year that is divisible by 4 except for years that are divisible by 100 but not divisible by 400. Thus 1996 was a leap year, as was 2000 (2000 is divisible by 400), but not 1700, 1800, or 1900 (1700, 1800 and 1900 are divisible by 100 but not divisible by 400).
Your task is to write a method, count, which takes a
Definition
- Class:
- BlueMoons
- Method:
- count
- Parameters:
- String, String
- Returns:
- int
- Method signature:
- int count(String interval, String fullMoon)
- (be sure your method is public)
Notes
- If a full moon occurs at 12AM (Midnight) it is part of the day which has just started, not the one that has just finished.
Constraints
- interval will be formatted exactly as "MM/YYYY to MM/YYYY", with no leading, trailing, or extra spaces.
- fullMoon will be formatted exactly as "DD.DD/MM/YYYY", with no leading or trailing spaces.
- Each MM will contain leading 0's, if necessary, to have exactly 2 digits.
- DD.DD will contain leading and trailing 0's if necessary so that it is always formatted as "DD.DD"
- All dates and times will be valid times since 1900, inclusive. Thus "MM" will be between "01" and "12", inclusive, "YYYY" will be between "1900" and "9999" inclusive, and "DD.DD" will be between "01.00" and "31.99" (depending on the month, the upper bound for the day could be lower), inclusive.
Examples
"01/2002 to 05/2002"
"28.95/01/2002"
Returns: 0
Given that there was a full moon at the specified time, there are no blue moons during this period.
"01/1900 to 12/1999"
"28.95/01/2002"
Returns: 41
"01/2000 to 12/2002"
"28.95/01/2002"
Returns: 1
There are two full moons in November (the 11th month) 2001. The second full moon is at 30.89/11/2001.
"01/2002 to 05/2002"
"01.00/01/2002"
Returns: 2
"01/2002 to 01/2002"
"02.46/01/2002"
Returns: 1
"01/2002 to 01/3002"
"02.46/01/1902"
Returns: 411
"01/2002 to 01/2002"
"02.47/01/2002"
Returns: 0
"01/1900 to 12/9999"
"02.47/01/2002"
Returns: 3338
"01/2002 to 01/2002"
"01.00/02/2002"
Returns: 0
Note that fullMoon need not be within interval.
"12/8817 to 11/9053"
"28.31/02/2126"
Returns: 97
"01/4456 to 07/7380"
"02.83/03/6724"
Returns: 1203
"05/3727 to 02/7375"
"03.05/07/7838"
Returns: 1504
"07/3159 to 05/4905"
"04.30/04/8007"
Returns: 720
"11/6961 to 12/8388"
"16.89/03/5058"
Returns: 588
"05/9240 to 09/9684"
"16.78/08/2319"
Returns: 184
"07/5194 to 05/5520"
"22.45/08/5395"
Returns: 134
"03/5508 to 08/7468"
"29.86/01/5096"
Returns: 807
"02/9784 to 05/9834"
"12.17/03/2436"
Returns: 21
"07/3392 to 11/4479"
"24.93/07/6299"
Returns: 449
"09/5704 to 08/9741"
"15.85/01/2802"
Returns: 1662
"04/2255 to 10/9113"
"18.77/08/3469"
Returns: 2828
"05/9260 to 12/9686"
"14.94/12/7070"
Returns: 176
"07/3655 to 07/9277"
"23.28/09/2255"
Returns: 2319
"05/7618 to 09/8481"
"22.94/12/5628"
Returns: 358
"01/7749 to 06/8600"
"31.49/10/5564"
Returns: 351
"04/4131 to 07/9379"
"16.31/09/3199"
Returns: 2162
"02/8900 to 08/9993"
"16.27/05/6800"
Returns: 454
"02/5030 to 02/5827"
"29.15/07/3758"
Returns: 328
"08/9707 to 12/9827"
"17.94/12/4081"
Returns: 50
"08/2560 to 11/5181"
"15.13/04/4325"
Returns: 1081
"01/4701 to 08/5822"
"03.37/06/5715"
Returns: 461
"03/8640 to 08/9593"
"12.45/12/7844"
Returns: 392
"03/8087 to 04/8768"
"31.63/03/5526"
Returns: 283
"02/4702 to 11/5845"
"05.64/06/6490"
Returns: 469
"10/3694 to 12/9993"
"27.49/10/2581"
Returns: 2593
"11/2010 to 10/8131"
"26.84/10/4892"
Returns: 2522
"02/3413 to 10/4668"
"11.67/03/5223"
Returns: 518
"11/9330 to 11/9331"
"11.51/07/9203"
Returns: 0
"01/2692 to 10/3896"
"12.30/10/9511"
Returns: 494
"10/8942 to 10/9667"
"15.54/04/6082"
Returns: 298
"04/6740 to 11/7076"
"29.19/09/1984"
Returns: 139
"03/7301 to 03/7495"
"18.38/01/6453"
Returns: 79
"05/6210 to 11/9881"
"01.32/03/6024"
Returns: 1514
"01/1952 to 01/3952"
"18.06/02/8510"
Returns: 823
"11/7331 to 08/8705"
"18.09/10/2093"
Returns: 567
"03/9662 to 03/9886"
"20.73/11/3828"
Returns: 91
"07/4299 to 06/7290"
"21.03/04/4411"
Returns: 1232
"01/7915 to 01/9178"
"30.64/11/8286"
Returns: 522
"11/6803 to 08/7447"
"11.86/04/5672"
Returns: 265
"11/6239 to 02/7095"
"26.59/08/9388"
Returns: 353
"08/3925 to 05/8453"
"27.84/01/4854"
Returns: 1865
"11/5773 to 08/6153"
"31.07/01/2043"
Returns: 156
"12/3045 to 08/8677"
"09.74/10/6163"
Returns: 2323
"12/5104 to 02/6022"
"18.76/07/8844"
Returns: 379
"04/5337 to 06/7131"
"06.43/10/3563"
Returns: 737
"01/4203 to 05/7402"
"25.15/04/8848"
Returns: 1318
"06/8020 to 08/8780"
"30.53/05/5505"
Returns: 313
"06/1915 to 11/9687"
"06.33/07/5216"
Returns: 3202
"07/7649 to 10/7968"
"26.95/12/8696"
Returns: 128
"07/4953 to 09/6672"
"02.14/04/8223"
Returns: 706
"03/2638 to 10/9973"
"18.51/07/3757"
Returns: 3021
"09/8187 to 01/8542"
"14.31/09/6729"
Returns: 148
"02/9411 to 01/9660"
"12.82/12/4709"
Returns: 101
"07/5288 to 08/5803"
"16.14/11/6624"
Returns: 212
"02/4917 to 02/6207"
"04.84/01/8736"
Returns: 533
"01/1913 to 05/9999"
"27.26/01/2002"
Returns: 3334
"01/1900 to 12/9999"
"05.75/05/2002"
Returns: 3335
"01/1900 to 12/9999"
"01.99/01/9999"
Returns: 3337
"01/3402 to 01/6002"
"01.00/02/2002"
Returns: 1077
"01/1900 to 05/9999"
"28.95/01/2002"
Returns: 3338
"01/1900 to 12/9999"
"01.00/01/2002"
Returns: 3336
"01/2002 to 03/2002"
"30.99/01/2002"
Returns: 2
"01/3402 to 01/7002"
"01.00/02/2002"
Returns: 1487
"03/1900 to 09/9099"
"21.03/04/9994"
Returns: 2969
"01/5002 to 05/9999"
"01.00/01/1900"
Returns: 2059
"03/2000 to 03/2000"
"01.00/02/2000"
Returns: 1
"01/3000 to 05/9999"
"01.00/01/1900"
Returns: 2883
"01/2004 to 01/2004"
"28.99/02/2004"
Returns: 0
"04/1900 to 05/9490"
"04.34/09/9988"
Returns: 3126
"04/8713 to 04/8713"
"21.00/04/8713"
Returns: 0