Skip to content

Instantly share code, notes, and snippets.

@nsmgr8
Last active April 22, 2020 11:49
Show Gist options
  • Save nsmgr8/f21bb1bec47ab6f3d179227113e18bc5 to your computer and use it in GitHub Desktop.
Save nsmgr8/f21bb1bec47ab6f3d179227113e18bc5 to your computer and use it in GitHub Desktop.
#!/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