Statistics

Problem Statement for "DigitalCounter"

Problem Statement

We have an N-digit digital counter that increments every second. The counter is cyclic: after it reaches 10^N - 1, it starts once again from zero.

Each digit is shown using the standard seven-segment display. The exact forms of all the digits are shown in the ASCII art below.

    +   +---+   +---+   +   +   +---+
    |       |       |   |   |   |
    +   +---+   +---+   +---+   +---+
    |   |           |       |       |
    +   +---+   +---+       +   +---+

+---+   +---+   +---+   +---+   +---+
|           |   |   |   |   |   |   |
+---+       +   +---+   +---+   +   +
|   |       |   |   |       |   |   |
+---+       +   +---+       +   +---+

Each line segment that connects two adjacent '+' symbols represents a single lit segment. For example, '1' contains two lit segments, and '9' contains five lit segments.

You are given a String current that contains the current number shown by the counter.
The number of characters in current is equal to the number N of displayed digits.

Return the smallest positive number of seconds after which the counter will have the same total number of lit segments as it does now.

Definition

Class:
DigitalCounter
Method:
nextEvent
Parameters:
String
Returns:
long
Method signature:
long nextEvent(String current)
(be sure your method is public)

Notes

  • The digits 1, 2, ..., 9, and 0 have 2, 5, 5, 4, 5, 6, 3, 7, 5, and 6 lit segments, respectively.
  • The counter does always show leading zeroes. (See Examples #3 and #5.)
  • As the counter is cyclic, the answer always exists and for any valid input the answer fits into a long.

Constraints

  • current will contain between 1 and 15 characters, inclusive.
  • Each character in current will be a digit ('0'-'9').

Examples

  1. "1"

    Returns: 10

    No other digit has exactly two segments lit, thus the next time there will be two segments lit will be in 10 seconds.

  2. "3"

    Returns: 2

    In 2 seconds the display will show "5", and "5" and "3" both have exactly five lit segments.

  3. "9"

    Returns: 3

    In 3 seconds, the display will show "2".

  4. "99"

    Returns: 5

    The number "99" is shown using 5+5=10 lit segments. In 5 seconds, the display will show "04", with 6+4=10 lit segments again.

  5. "888888888888888"

    Returns: 1000000000000000

  6. "988888888888888"

    Returns: 20000000000000

  7. "654371"

    Returns: 43

  8. "999"

    Returns: 8

  9. "12542352325125"

    Returns: 4

  10. "124127777777"

    Returns: 134

  11. "124288888888"

    Returns: 100000000

  12. "12428888811111"

    Returns: 100003

  13. "111111111111111"

    Returns: 1000000000000000

  14. "322222222222222"

    Returns: 1

  15. "388888888888888"

    Returns: 200000000000000

  16. "788888888888888"

    Returns: 11120000000000

  17. "000000000000000"

    Returns: 6

  18. "000000000000001"

    Returns: 9

  19. "030133652081062"

    Returns: 1

  20. "056833948135792"

    Returns: 1

  21. "05713470"

    Returns: 6

  22. "057134701111111"

    Returns: 9000000

  23. "057134708888888"

    Returns: 60000000

  24. "065927413"

    Returns: 2

  25. "065927413111111"

    Returns: 1000006

  26. "065927413888888"

    Returns: 2000000

  27. "1072221"

    Returns: 10

  28. "107222111111111"

    Returns: 1000000000

  29. "107222188888888"

    Returns: 11200000

  30. "226403832336"

    Returns: 12

  31. "226403832336111"

    Returns: 1001

  32. "226403832336888"

    Returns: 1200

  33. "2330"

    Returns: 6

  34. "233011111111111"

    Returns: 90000000000

  35. "233088888888888"

    Returns: 600000000000

  36. "23897035"

    Returns: 4

  37. "238970351111111"

    Returns: 20000003

  38. "238970358888888"

    Returns: 2000000

  39. "247975864814"

    Returns: 27

  40. "247975864814111"

    Returns: 3006

  41. "247975864814888"

    Returns: 200

  42. "30516305653579"

    Returns: 18

  43. "305163056535791"

    Returns: 126

  44. "305163056535798"

    Returns: 3

  45. "3312230888772"

    Returns: 1

  46. "331223088877211"

    Returns: 100

  47. "331223088877288"

    Returns: 100

  48. "39023125"

    Returns: 4

  49. "390231251111111"

    Returns: 20000003

  50. "390231258888888"

    Returns: 2000000

  51. "4"

    Returns: 10

  52. "41002008254663"

    Returns: 2

  53. "410020082546631"

    Returns: 16

  54. "410020082546638"

    Returns: 20

  55. "411111111111111"

    Returns: 300000000000006

  56. "421905125"

    Returns: 4

  57. "421905125111111"

    Returns: 2000003

  58. "421905125888888"

    Returns: 200000

  59. "44974872362"

    Returns: 1

  60. "449748723621111"

    Returns: 10000

  61. "449748723628888"

    Returns: 10000

  62. "488888888888888"

    Returns: 20000000000000

  63. "50144227913925"

    Returns: 4

  64. "501442279139251"

    Returns: 23

  65. "501442279139258"

    Returns: 2

  66. "52846"

    Returns: 6

  67. "528461111111111"

    Returns: 10000000001

  68. "528468888888888"

    Returns: 12000000000

  69. "61731363885861"

    Returns: 11

  70. "617313638858611"

    Returns: 101

  71. "617313638858618"

    Returns: 6

  72. "62238363597"

    Returns: 15

  73. "622383635971111"

    Returns: 140001

  74. "622383635978888"

    Returns: 1112

  75. "62731107981"

    Returns: 13

  76. "627311079811111"

    Returns: 100003

  77. "627311079818888"

    Returns: 1120

  78. "65151"

    Returns: 23

  79. "651511111111111"

    Returns: 200000000003

  80. "651518888888888"

    Returns: 1120000000

  81. "65922"

    Returns: 1

  82. "659221111111111"

    Returns: 10000000000

  83. "659228888888888"

    Returns: 10000000000

  84. "6829110500"

    Returns: 6

  85. "682911050011111"

    Returns: 90000

  86. "682911050088888"

    Returns: 600000

  87. "7"

    Returns: 10

  88. "711111111111111"

    Returns: 400000000000006

  89. "779825967"

    Returns: 3

  90. "779825967111111"

    Returns: 3000000

  91. "779825967888888"

    Returns: 111200

  92. "788888888888888"

    Returns: 11120000000000

  93. "8120409870"

    Returns: 6

  94. "812040987011111"

    Returns: 90000

  95. "812040987088888"

    Returns: 600000

  96. "87338"

    Returns: 20

  97. "873381111111111"

    Returns: 10000000003

  98. "873388888888888"

    Returns: 200000000000

  99. "9115006"

    Returns: 22

  100. "911500611111111"

    Returns: 100000001

  101. "911500688888888"

    Returns: 120000000

  102. "235232555255555"

    Returns: 4

  103. "235232999999999"

    Returns: 113

  104. "007"

    Returns: 11

    Note that the input can have leading zeroes.

  105. "111117111111111"

    Returns: 54000000000

  106. "88888888888888"

    Returns: 100000000000000

  107. "002438414123697"

    Returns: 5

  108. "117177111111111"

    Returns: 234000000000

  109. "188888888888888"

    Returns: 11200000000000

  110. "887888888888888"

    Returns: 111200000000

  111. "889888888888888"

    Returns: 9000000000000

  112. "99991234567876"

    Returns: 5

  113. "12384523068978"

    Returns: 9

  114. "123456789123456"

    Returns: 6

  115. "998888888888"

    Returns: 1200000000

  116. "7687612160"

    Returns: 6

  117. "899999999999999"

    Returns: 112

  118. "111111111111"

    Returns: 1000000000000

  119. "123456789101129"

    Returns: 3

  120. "000100000000007"

    Returns: 11

  121. "654371111111111"

    Returns: 40000000003

  122. "688888888888888"

    Returns: 120000000000000


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: