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
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"
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.
"3"
Returns: 2
In 2 seconds the display will show "5", and "5" and "3" both have exactly five lit segments.
"9"
Returns: 3
In 3 seconds, the display will show "2".
"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.
"888888888888888"
Returns: 1000000000000000
"988888888888888"
Returns: 20000000000000
"654371"
Returns: 43
"999"
Returns: 8
"12542352325125"
Returns: 4
"124127777777"
Returns: 134
"124288888888"
Returns: 100000000
"12428888811111"
Returns: 100003
"111111111111111"
Returns: 1000000000000000
"322222222222222"
Returns: 1
"388888888888888"
Returns: 200000000000000
"788888888888888"
Returns: 11120000000000
"000000000000000"
Returns: 6
"000000000000001"
Returns: 9
"030133652081062"
Returns: 1
"056833948135792"
Returns: 1
"05713470"
Returns: 6
"057134701111111"
Returns: 9000000
"057134708888888"
Returns: 60000000
"065927413"
Returns: 2
"065927413111111"
Returns: 1000006
"065927413888888"
Returns: 2000000
"1072221"
Returns: 10
"107222111111111"
Returns: 1000000000
"107222188888888"
Returns: 11200000
"226403832336"
Returns: 12
"226403832336111"
Returns: 1001
"226403832336888"
Returns: 1200
"2330"
Returns: 6
"233011111111111"
Returns: 90000000000
"233088888888888"
Returns: 600000000000
"23897035"
Returns: 4
"238970351111111"
Returns: 20000003
"238970358888888"
Returns: 2000000
"247975864814"
Returns: 27
"247975864814111"
Returns: 3006
"247975864814888"
Returns: 200
"30516305653579"
Returns: 18
"305163056535791"
Returns: 126
"305163056535798"
Returns: 3
"3312230888772"
Returns: 1
"331223088877211"
Returns: 100
"331223088877288"
Returns: 100
"39023125"
Returns: 4
"390231251111111"
Returns: 20000003
"390231258888888"
Returns: 2000000
"4"
Returns: 10
"41002008254663"
Returns: 2
"410020082546631"
Returns: 16
"410020082546638"
Returns: 20
"411111111111111"
Returns: 300000000000006
"421905125"
Returns: 4
"421905125111111"
Returns: 2000003
"421905125888888"
Returns: 200000
"44974872362"
Returns: 1
"449748723621111"
Returns: 10000
"449748723628888"
Returns: 10000
"488888888888888"
Returns: 20000000000000
"50144227913925"
Returns: 4
"501442279139251"
Returns: 23
"501442279139258"
Returns: 2
"52846"
Returns: 6
"528461111111111"
Returns: 10000000001
"528468888888888"
Returns: 12000000000
"61731363885861"
Returns: 11
"617313638858611"
Returns: 101
"617313638858618"
Returns: 6
"62238363597"
Returns: 15
"622383635971111"
Returns: 140001
"622383635978888"
Returns: 1112
"62731107981"
Returns: 13
"627311079811111"
Returns: 100003
"627311079818888"
Returns: 1120
"65151"
Returns: 23
"651511111111111"
Returns: 200000000003
"651518888888888"
Returns: 1120000000
"65922"
Returns: 1
"659221111111111"
Returns: 10000000000
"659228888888888"
Returns: 10000000000
"6829110500"
Returns: 6
"682911050011111"
Returns: 90000
"682911050088888"
Returns: 600000
"7"
Returns: 10
"711111111111111"
Returns: 400000000000006
"779825967"
Returns: 3
"779825967111111"
Returns: 3000000
"779825967888888"
Returns: 111200
"788888888888888"
Returns: 11120000000000
"8120409870"
Returns: 6
"812040987011111"
Returns: 90000
"812040987088888"
Returns: 600000
"87338"
Returns: 20
"873381111111111"
Returns: 10000000003
"873388888888888"
Returns: 200000000000
"9115006"
Returns: 22
"911500611111111"
Returns: 100000001
"911500688888888"
Returns: 120000000
"235232555255555"
Returns: 4
"235232999999999"
Returns: 113
"007"
Returns: 11
Note that the input can have leading zeroes.
"111117111111111"
Returns: 54000000000
"88888888888888"
Returns: 100000000000000
"002438414123697"
Returns: 5
"117177111111111"
Returns: 234000000000
"188888888888888"
Returns: 11200000000000
"887888888888888"
Returns: 111200000000
"889888888888888"
Returns: 9000000000000
"99991234567876"
Returns: 5
"12384523068978"
Returns: 9
"123456789123456"
Returns: 6
"998888888888"
Returns: 1200000000
"7687612160"
Returns: 6
"899999999999999"
Returns: 112
"111111111111"
Returns: 1000000000000
"123456789101129"
Returns: 3
"000100000000007"
Returns: 11
"654371111111111"
Returns: 40000000003
"688888888888888"
Returns: 120000000000000