aboutsummaryrefslogtreecommitdiff
path: root/challenge-282/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-09-05 18:43:38 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-09-05 18:43:38 +0100
commit73c1b95cf0dd273786e892c654a76da97658eea1 (patch)
treeb8d09032813e9525bed2db20025d4fb9bb5b50f2 /challenge-282/paulo-custodio/python/ch-1.py
parentf10dac9c38d04b762a0ce20fb1be160fd0d9b02c (diff)
downloadperlweeklychallenge-club-73c1b95cf0dd273786e892c654a76da97658eea1.tar.gz
perlweeklychallenge-club-73c1b95cf0dd273786e892c654a76da97658eea1.tar.bz2
perlweeklychallenge-club-73c1b95cf0dd273786e892c654a76da97658eea1.zip
Add Python solution to challenge 282
Diffstat (limited to 'challenge-282/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-282/paulo-custodio/python/ch-1.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-282/paulo-custodio/python/ch-1.py b/challenge-282/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..c64a2229d4
--- /dev/null
+++ b/challenge-282/paulo-custodio/python/ch-1.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+# Challenge 282
+#
+# Task 1: Good Integer
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given a positive integer, $int, having 3 or more digits.
+#
+# Write a script to return the Good Integer in the given integer or -1
+# if none found.
+#
+# A good integer is exactly three consecutive matching digits.
+#
+# Example 1
+#
+# Input: $int = 12344456
+# Output: 444
+#
+# Example 2
+#
+# Input: $int = 1233334
+# Output: -1
+#
+# Example 3
+#
+# Input: $int = 10020003
+# Output: 000
+
+import re
+import sys
+
+found = re.search(r'((\d)\2\2+)', sys.argv[1])
+if found is None:
+ print(-1)
+elif len(found.group(1)) != 3:
+ print(-1)
+else:
+ print(found.group(1))