Statistics

Problem Statement for "BlueMoons"

Problem Statement

For the purposes of this problem, there are exactly 29.53 days between two full moons. A blue moon occurs whenever there is a full moon twice in one calendar month (January, February, etc). For example, if a full moon occurs at some point on January 1st, then another one will occur at some point on January 30th or 31st (depending on what time it occurred on the 1st). The second one is the blue moon.

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:
  1. Every year has 12 months.
  2. 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
  3. In leap years, the second month (February) has 29 days instead of 28.
  4. 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 String, interval, and another String, fullMoon, as input and determines how many blue moons there are in that interval. interval will be formatted as "MM/YYYY to MM/YYYY" where "MM" represents the month (January is "01" and December is "12") and "YYYY" represents the year. fullMoon will represent a specific time at which there was a full moon and will be formatted as "DD.DD/MM/YYYY" where "MM" and "YYYY" are formatted the same as they are in interval. "DD.DD" represents the day of the month, as a fraction. Thus "01.00" would mean 12 AM on the first day of the month. "01.50" would be exactly half way through the first day of the month (12 NOON). Thus, if fullMoon were "05.75/05/2002", this would mean that there was a full moon precisely 3 quarters of the way through the 5th day of the 5th month of 2002 (6 PM May 5th 2002).

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

  1. "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.

  2. "01/1900 to 12/1999"

    "28.95/01/2002"

    Returns: 41

  3. "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.

  4. "01/2002 to 05/2002"

    "01.00/01/2002"

    Returns: 2

  5. "01/2002 to 01/2002"

    "02.46/01/2002"

    Returns: 1

  6. "01/2002 to 01/3002"

    "02.46/01/1902"

    Returns: 411

  7. "01/2002 to 01/2002"

    "02.47/01/2002"

    Returns: 0

  8. "01/1900 to 12/9999"

    "02.47/01/2002"

    Returns: 3338

  9. "01/2002 to 01/2002"

    "01.00/02/2002"

    Returns: 0

    Note that fullMoon need not be within interval.

  10. "12/8817 to 11/9053"

    "28.31/02/2126"

    Returns: 97

  11. "01/4456 to 07/7380"

    "02.83/03/6724"

    Returns: 1203

  12. "05/3727 to 02/7375"

    "03.05/07/7838"

    Returns: 1504

  13. "07/3159 to 05/4905"

    "04.30/04/8007"

    Returns: 720

  14. "11/6961 to 12/8388"

    "16.89/03/5058"

    Returns: 588

  15. "05/9240 to 09/9684"

    "16.78/08/2319"

    Returns: 184

  16. "07/5194 to 05/5520"

    "22.45/08/5395"

    Returns: 134

  17. "03/5508 to 08/7468"

    "29.86/01/5096"

    Returns: 807

  18. "02/9784 to 05/9834"

    "12.17/03/2436"

    Returns: 21

  19. "07/3392 to 11/4479"

    "24.93/07/6299"

    Returns: 449

  20. "09/5704 to 08/9741"

    "15.85/01/2802"

    Returns: 1662

  21. "04/2255 to 10/9113"

    "18.77/08/3469"

    Returns: 2828

  22. "05/9260 to 12/9686"

    "14.94/12/7070"

    Returns: 176

  23. "07/3655 to 07/9277"

    "23.28/09/2255"

    Returns: 2319

  24. "05/7618 to 09/8481"

    "22.94/12/5628"

    Returns: 358

  25. "01/7749 to 06/8600"

    "31.49/10/5564"

    Returns: 351

  26. "04/4131 to 07/9379"

    "16.31/09/3199"

    Returns: 2162

  27. "02/8900 to 08/9993"

    "16.27/05/6800"

    Returns: 454

  28. "02/5030 to 02/5827"

    "29.15/07/3758"

    Returns: 328

  29. "08/9707 to 12/9827"

    "17.94/12/4081"

    Returns: 50

  30. "08/2560 to 11/5181"

    "15.13/04/4325"

    Returns: 1081

  31. "01/4701 to 08/5822"

    "03.37/06/5715"

    Returns: 461

  32. "03/8640 to 08/9593"

    "12.45/12/7844"

    Returns: 392

  33. "03/8087 to 04/8768"

    "31.63/03/5526"

    Returns: 283

  34. "02/4702 to 11/5845"

    "05.64/06/6490"

    Returns: 469

  35. "10/3694 to 12/9993"

    "27.49/10/2581"

    Returns: 2593

  36. "11/2010 to 10/8131"

    "26.84/10/4892"

    Returns: 2522

  37. "02/3413 to 10/4668"

    "11.67/03/5223"

    Returns: 518

  38. "11/9330 to 11/9331"

    "11.51/07/9203"

    Returns: 0

  39. "01/2692 to 10/3896"

    "12.30/10/9511"

    Returns: 494

  40. "10/8942 to 10/9667"

    "15.54/04/6082"

    Returns: 298

  41. "04/6740 to 11/7076"

    "29.19/09/1984"

    Returns: 139

  42. "03/7301 to 03/7495"

    "18.38/01/6453"

    Returns: 79

  43. "05/6210 to 11/9881"

    "01.32/03/6024"

    Returns: 1514

  44. "01/1952 to 01/3952"

    "18.06/02/8510"

    Returns: 823

  45. "11/7331 to 08/8705"

    "18.09/10/2093"

    Returns: 567

  46. "03/9662 to 03/9886"

    "20.73/11/3828"

    Returns: 91

  47. "07/4299 to 06/7290"

    "21.03/04/4411"

    Returns: 1232

  48. "01/7915 to 01/9178"

    "30.64/11/8286"

    Returns: 522

  49. "11/6803 to 08/7447"

    "11.86/04/5672"

    Returns: 265

  50. "11/6239 to 02/7095"

    "26.59/08/9388"

    Returns: 353

  51. "08/3925 to 05/8453"

    "27.84/01/4854"

    Returns: 1865

  52. "11/5773 to 08/6153"

    "31.07/01/2043"

    Returns: 156

  53. "12/3045 to 08/8677"

    "09.74/10/6163"

    Returns: 2323

  54. "12/5104 to 02/6022"

    "18.76/07/8844"

    Returns: 379

  55. "04/5337 to 06/7131"

    "06.43/10/3563"

    Returns: 737

  56. "01/4203 to 05/7402"

    "25.15/04/8848"

    Returns: 1318

  57. "06/8020 to 08/8780"

    "30.53/05/5505"

    Returns: 313

  58. "06/1915 to 11/9687"

    "06.33/07/5216"

    Returns: 3202

  59. "07/7649 to 10/7968"

    "26.95/12/8696"

    Returns: 128

  60. "07/4953 to 09/6672"

    "02.14/04/8223"

    Returns: 706

  61. "03/2638 to 10/9973"

    "18.51/07/3757"

    Returns: 3021

  62. "09/8187 to 01/8542"

    "14.31/09/6729"

    Returns: 148

  63. "02/9411 to 01/9660"

    "12.82/12/4709"

    Returns: 101

  64. "07/5288 to 08/5803"

    "16.14/11/6624"

    Returns: 212

  65. "02/4917 to 02/6207"

    "04.84/01/8736"

    Returns: 533

  66. "01/1913 to 05/9999"

    "27.26/01/2002"

    Returns: 3334

  67. "01/1900 to 12/9999"

    "05.75/05/2002"

    Returns: 3335

  68. "01/1900 to 12/9999"

    "01.99/01/9999"

    Returns: 3337

  69. "01/3402 to 01/6002"

    "01.00/02/2002"

    Returns: 1077

  70. "01/1900 to 05/9999"

    "28.95/01/2002"

    Returns: 3338

  71. "01/1900 to 12/9999"

    "01.00/01/2002"

    Returns: 3336

  72. "01/2002 to 03/2002"

    "30.99/01/2002"

    Returns: 2

  73. "01/3402 to 01/7002"

    "01.00/02/2002"

    Returns: 1487

  74. "03/1900 to 09/9099"

    "21.03/04/9994"

    Returns: 2969

  75. "01/5002 to 05/9999"

    "01.00/01/1900"

    Returns: 2059

  76. "03/2000 to 03/2000"

    "01.00/02/2000"

    Returns: 1

  77. "01/3000 to 05/9999"

    "01.00/01/1900"

    Returns: 2883

  78. "01/2004 to 01/2004"

    "28.99/02/2004"

    Returns: 0

  79. "04/1900 to 05/9490"

    "04.34/09/9988"

    Returns: 3126

  80. "04/8713 to 04/8713"

    "21.00/04/8713"

    Returns: 0


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: