diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-05 20:28:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-05 20:28:05 +0100 |
| commit | e3a3db8e940a41a2bb87b9d3654aed33f94da7fd (patch) | |
| tree | b8d09032813e9525bed2db20025d4fb9bb5b50f2 /challenge-282/paulo-custodio/python/ch-1.py | |
| parent | f954b76daf066bbe93d1dc1c11cd56b99b0e37e9 (diff) | |
| parent | 73c1b95cf0dd273786e892c654a76da97658eea1 (diff) | |
| download | perlweeklychallenge-club-e3a3db8e940a41a2bb87b9d3654aed33f94da7fd.tar.gz perlweeklychallenge-club-e3a3db8e940a41a2bb87b9d3654aed33f94da7fd.tar.bz2 perlweeklychallenge-club-e3a3db8e940a41a2bb87b9d3654aed33f94da7fd.zip | |
Merge pull request #10774 from pauloscustodio/master
Add Python solutions
Diffstat (limited to 'challenge-282/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-282/paulo-custodio/python/ch-1.py | 39 |
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)) |
