aboutsummaryrefslogtreecommitdiff
path: root/challenge-282/sgreen/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-282/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-282/sgreen/python/ch-1.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-282/sgreen/python/ch-1.py b/challenge-282/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..91178462c1
--- /dev/null
+++ b/challenge-282/sgreen/python/ch-1.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def good_integer(n: int) -> str:
+ # Convert the integer to a string
+ value = str(n)
+ length = len(value)
+
+ for pos in range(length-2):
+ if (
+ value[pos] == value[pos+1]
+ and value[pos] == value[pos+2]
+ and (pos == 0 or value[pos] != value[pos-1])
+ and (pos + 3 == length or value[pos] != value[pos+3])
+ ):
+ return value[pos:pos+3]
+
+ return '-1'
+
+
+def main():
+ # Convert input into an integer
+ result = good_integer(int(sys.argv[1]))
+ print(result)
+
+
+if __name__ == '__main__':
+ main()