Last active
April 22, 2020 11:49
-
-
Save nsmgr8/f21bb1bec47ab6f3d179227113e18bc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import re | |
import sys | |
try: | |
number = sys.argv[1] | |
except IndexError: | |
number = '45333312884443' | |
store = {} | |
for match in re.finditer(r'(\d)\1*', number): | |
digit = match.groups()[0] | |
start, end = match.span() | |
length = end - start | |
if store.get(digit, {}).get('length', 0) < length: | |
store[digit] = { | |
'digit': digit, | |
'length': length, | |
'position': start + 1, | |
} | |
result = max(store.values(), key=lambda x: x['length']) | |
print(f""" | |
Input: {number} | |
Consecutive digit: {result['digit']} | |
Length: {result['length']} | |
Position: {result['position']} | |
""") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment