Statistics

Problem Statement for "BadClock"

Problem Statement

According to Lewis Carroll, a clock that has stopped is more accurate than one that is five minutes behind. He argues that the former is right twice a day, whereas the latter never shows the correct time. Then again, a clock that is always five minutes behind is in a sense perfectly accurate, and therefore an extraordinary specimen. More usually, a clock is ahead or behind because it runs at the wrong rate, so that its absolute discrepancy from the true time is steadily changing. If left unregulated, such a clock will show the true time at regular but perhaps lengthy intervals.

You are given two Strings of the form "hh:mm:ss". The first represents exactly the true time, while the second is exactly the time shown by an ill-tuned clock. This is an analog clock whose hour, minute, and second hands sweep continuously around the dial at a speed that is too fast or too slow by a constant factor. Both times are given in the North American style, where the hour ranges between 1 and 12, inclusive. Given an int specifying the non-zero number of seconds that the clock gains every hour, calculate the number of hours that elapse before it agrees with the true time. Your answer, a double, must be correct with either absolute or relative precision of 1.0e-9 (one billionth).

Definition

Class:
BadClock
Method:
nextAgreement
Parameters:
String, String, int
Returns:
double
Method signature:
double nextAgreement(String trueTime, String skewTime, int hourlyGain)
(be sure your method is public)

Notes

  • If hourlyGain is negative, the clock falls behind by a fixed number of seconds every hour.
  • It is not the case that the clock makes discrete jumps every so often. Rather, the hands of the clock are moving smoothly and continuously at a constant rate that is too slow or too fast relative to the true time.

Constraints

  • trueTime and skewTime each contain exactly eight characters in the format "hh:mm:ss", where the substring "hh" is a zero-padded integer between 1 and 12, inclusive, and "mm" and "ss" are zero-padded integers between 0 and 59, inclusive
  • hourlyGain is either between -1800 and -1, inclusive, or between 1 and 3600, inclusive

Examples

  1. "07:07:07"

    "07:07:07"

    1776

    Returns: 0.0

    The clock is already showing the true time.

  2. "11:59:58"

    "12:03:28"

    -3

    Returns: 70.0

    This clock loses three seconds every hour, and will catch up with the true time in exactly 70 hours.

  3. "12:03:28"

    "11:59:58"

    3

    Returns: 70.0

    This clock gains three seconds per hour.

  4. "03:03:02"

    "03:01:47"

    5

    Returns: 15.0

  5. "03:03:02"

    "03:01:47"

    -5

    Returns: 8625.0

  6. "07:08:09"

    "09:08:07"

    -321

    Returns: 22.42367601246106

  7. "11:59:59"

    "12:00:00"

    3600

    Returns: 11.999722222222223

  8. "11:59:59"

    "12:00:00"

    1

    Returns: 43199.0

  9. "12:00:00"

    "11:59:59"

    -1800

    Returns: 23.999444444444446

  10. "12:00:00"

    "11:59:59"

    -1

    Returns: 43199.0

  11. "03:03:48"

    "09:30:25"

    2337

    Returns: 8.559264013692768

  12. "03:19:53"

    "03:02:36"

    1148

    Returns: 0.9033101045296167

  13. "09:32:36"

    "07:43:29"

    1268

    Returns: 5.163249211356467

  14. "08:26:33"

    "12:21:10"

    1253

    Returns: 23.24261771747805

  15. "08:06:10"

    "01:50:05"

    -1394

    Returns: 14.802725968436155

  16. "12:12:13"

    "02:24:59"

    1756

    Returns: 20.06492027334852

  17. "12:37:35"

    "07:07:35"

    -935

    Returns: 25.02673796791444

  18. "08:13:20"

    "03:16:20"

    2437

    Returns: 7.312269183422241

  19. "02:19:21"

    "04:37:59"

    -1213

    Returns: 6.857378400659522

  20. "02:14:14"

    "03:19:15"

    833

    Returns: 47.17767106842737

  21. "11:41:13"

    "02:13:53"

    -847

    Returns: 10.814639905548997

  22. "05:05:33"

    "01:34:23"

    1883

    Returns: 6.728624535315985

  23. "08:33:09"

    "01:38:19"

    2590

    Returns: 9.61003861003861

  24. "01:03:15"

    "12:03:09"

    -1204

    Returns: 32.88538205980066

  25. "09:28:30"

    "05:12:49"

    2314

    Returns: 6.629645635263612

  26. "08:09:26"

    "08:02:26"

    -687

    Returns: 62.2707423580786

  27. "10:31:51"

    "07:46:55"

    758

    Returns: 13.055408970976254

  28. "04:06:48"

    "03:43:32"

    -626

    Returns: 66.77955271565496

  29. "11:03:13"

    "11:52:32"

    2938

    Returns: 13.696732471068755

  30. "05:12:08"

    "10:02:47"

    778

    Returns: 33.11182519280206

  31. "06:47:01"

    "12:44:23"

    598

    Returns: 36.38461538461539

  32. "06:07:41"

    "11:35:41"

    -809

    Returns: 24.326328800988875

  33. "02:19:20"

    "12:02:21"

    -1595

    Returns: 21.93166144200627

  34. "01:20:50"

    "02:30:50"

    2033

    Returns: 19.183472700442696

  35. "06:31:44"

    "03:21:48"

    566

    Returns: 20.13427561837456

  36. "10:12:36"

    "02:22:26"

    2720

    Returns: 10.371323529411764

  37. "03:19:54"

    "06:36:45"

    -243

    Returns: 48.60493827160494

  38. "04:38:33"

    "03:58:06"

    1948

    Returns: 1.245893223819302

  39. "06:23:13"

    "07:09:08"

    294

    Returns: 137.56802721088437

  40. "09:29:37"

    "07:31:34"

    2821

    Returns: 2.510811768876285

  41. "07:13:08"

    "05:34:25"

    -30

    Returns: 1242.5666666666666

  42. "12:23:43"

    "12:41:31"

    513

    Returns: 82.12865497076024

  43. "10:53:16"

    "02:34:07"

    688

    Returns: 43.530523255813954

  44. "02:58:27"

    "07:39:07"

    1091

    Returns: 24.161319890009167

  45. "06:30:06"

    "07:11:10"

    1440

    Returns: 28.288888888888888

  46. "10:01:11"

    "07:55:33"

    -1445

    Returns: 24.679584775086504

  47. "06:45:33"

    "04:59:39"

    -1684

    Returns: 21.880047505938244

  48. "08:38:09"

    "01:16:04"

    2267

    Returns: 11.700485222761358

  49. "06:47:39"

    "07:14:00"

    -478

    Returns: 3.307531380753138

  50. "08:50:39"

    "07:46:03"

    1402

    Returns: 2.7646219686162623

  51. "08:59:12"

    "10:10:06"

    3340

    Returns: 11.660479041916167

  52. "09:45:50"

    "01:18:19"

    671

    Returns: 45.38152011922504

  53. "12:17:03"

    "08:41:13"

    1363

    Returns: 9.501100513573

  54. "02:54:06"

    "01:09:13"

    2736

    Returns: 2.3000730994152048

  55. "11:32:05"

    "03:04:14"

    3568

    Returns: 8.540078475336323

  56. "03:55:13"

    "10:20:27"

    3382

    Returns: 5.9390892962743935

  57. "07:49:08"

    "07:29:41"

    3471

    Returns: 0.3362143474503025

  58. "07:08:53"

    "06:37:56"

    2462

    Returns: 0.7542648253452477

  59. "02:13:31"

    "03:09:54"

    2599

    Returns: 15.320123124278568

  60. "01:31:08"

    "11:33:39"

    2776

    Returns: 2.539265129682997

  61. "01:37:21"

    "01:00:49"

    1313

    Returns: 1.6694592536176696

  62. "09:07:52"

    "12:17:00"

    1576

    Returns: 20.210659898477157

  63. "05:24:05"

    "07:56:20"

    2830

    Returns: 12.037102473498233

  64. "10:58:21"

    "09:46:49"

    1364

    Returns: 3.1466275659824046

  65. "06:28:42"

    "09:12:25"

    -1700

    Returns: 5.778235294117647

  66. "12:32:25"

    "12:21:32"

    1271

    Returns: 0.5137686860739575

  67. "09:29:55"

    "09:57:26"

    3186

    Returns: 13.041117388575016

  68. "05:13:37"

    "08:23:58"

    230

    Returns: 138.1695652173913

  69. "05:41:30"

    "11:40:51"

    2705

    Returns: 7.999630314232902

  70. "01:28:54"

    "01:47:13"

    -1030

    Returns: 1.0669902912621358

  71. "02:48:53"

    "04:14:55"

    273

    Returns: 139.33333333333334

  72. "01:54:33"

    "03:49:31"

    -161

    Returns: 42.84472049689441

  73. "11:39:59"

    "06:44:20"

    -760

    Returns: 33.501315789473686

  74. "03:51:05"

    "07:18:32"

    1506

    Returns: 20.4203187250996

  75. "10:42:30"

    "07:40:38"

    145

    Returns: 75.2551724137931

  76. "08:04:01"

    "11:25:21"

    685

    Returns: 45.43065693430657

  77. "04:39:48"

    "10:03:14"

    2745

    Returns: 8.668123861566485

  78. "07:44:37"

    "02:36:26"

    3321

    Returns: 5.567901234567901

  79. "01:45:45"

    "11:17:38"

    -585

    Returns: 58.654700854700856

  80. "09:30:27"

    "03:54:36"

    2328

    Returns: 8.655927835051546

  81. "07:47:34"

    "05:13:01"

    3054

    Returns: 3.036345776031434

  82. "01:16:03"

    "06:16:31"

    640

    Returns: 39.33125

  83. "03:30:18"

    "04:44:34"

    2553

    Returns: 15.17587152369761

  84. "02:34:34"

    "02:17:25"

    -57

    Returns: 739.8421052631579

  85. "01:55:48"

    "11:05:51"

    -1500

    Returns: 22.002

  86. "03:47:18"

    "07:42:24"

    -1770

    Returns: 7.969491525423729

  87. "11:10:46"

    "06:30:15"

    3158

    Returns: 5.329639012032932

  88. "04:40:01"

    "02:14:50"

    -1195

    Returns: 28.861087866108786

  89. "07:07:08"

    "10:08:20"

    2668

    Returns: 12.116941529235381

  90. "05:38:32"

    "03:07:31"

    -1409

    Returns: 24.229240596167493

  91. "01:09:31"

    "05:37:53"

    -1349

    Returns: 11.936249073387694

  92. "10:57:32"

    "01:42:35"

    1454

    Returns: 22.900275103163686

  93. "09:49:14"

    "07:23:34"

    -887

    Returns: 38.8500563697858

  94. "03:30:11"

    "03:44:36"

    -1097

    Returns: 0.7885141294439381

  95. "11:43:37"

    "02:35:23"

    -1543

    Returns: 6.679196370706416

  96. "09:02:33"

    "03:09:46"

    -1514

    Returns: 14.552840158520475

  97. "04:53:25"

    "12:15:18"

    943

    Returns: 17.695652173913043

  98. "07:26:29"

    "12:29:13"

    -222

    Returns: 81.81981981981981

  99. "10:28:13"

    "12:19:28"

    2182

    Returns: 16.73923006416132

  100. "11:37:47"

    "06:30:41"

    -740

    Returns: 33.47837837837838

  101. "07:08:09"

    "09:08:07"

    -321

    Returns: 22.42367601246106

  102. "03:03:02"

    "03:01:47"

    -5

    Returns: 8625.0

  103. "07:07:07"

    "07:07:07"

    1776

    Returns: 0.0

  104. "03:03:02"

    "03:01:47"

    -10

    Returns: 4312.5

  105. "11:59:58"

    "12:03:28"

    3

    Returns: 14330.0

  106. "03:03:03"

    "03:03:02"

    -1

    Returns: 43199.0

  107. "11:00:00"

    "11:00:01"

    3600

    Returns: 11.999722222222223

  108. "07:07:07"

    "01:01:01"

    -1

    Returns: 21234.0

  109. "03:03:02"

    "03:01:47"

    -37

    Returns: 1165.5405405405406

  110. "01:01:01"

    "03:03:03"

    1

    Returns: 35878.0

  111. "07:08:09"

    "09:08:07"

    2

    Returns: 18001.0

  112. "01:00:00"

    "01:00:01"

    1

    Returns: 43199.0

  113. "12:00:00"

    "12:00:00"

    4

    Returns: 0.0

  114. "01:01:01"

    "01:01:02"

    1

    Returns: 43199.0

  115. "05:00:00"

    "06:00:00"

    1

    Returns: 39600.0

  116. "03:01:47"

    "03:03:02"

    5

    Returns: 8625.0

  117. "10:00:01"

    "10:00:02"

    1

    Returns: 43199.0

  118. "08:00:00"

    "10:00:00"

    10

    Returns: 3600.0

  119. "07:07:07"

    "07:07:07"

    -2

    Returns: 0.0

  120. "03:03:02"

    "03:04:47"

    3

    Returns: 14365.0

  121. "03:03:02"

    "03:01:47"

    -13

    Returns: 3317.3076923076924


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: