diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-08-18 15:09:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-18 15:09:16 +0100 |
| commit | d833fec8f6b78d515f045bcbe24f29e2ada46670 (patch) | |
| tree | cbff229e0221aa7330b135761d8953973c11bddc /challenge-282/sgreen/python/ch-1.py | |
| parent | 786a7af32b40f7790ca44a06db0b0295d2a15927 (diff) | |
| parent | add8d7fd4eb2ad39bd4e70bc0f2566b3d5528f21 (diff) | |
| download | perlweeklychallenge-club-d833fec8f6b78d515f045bcbe24f29e2ada46670.tar.gz perlweeklychallenge-club-d833fec8f6b78d515f045bcbe24f29e2ada46670.tar.bz2 perlweeklychallenge-club-d833fec8f6b78d515f045bcbe24f29e2ada46670.zip | |
Merge pull request #10637 from simongreen-net/master
sgreen solutions to challenge 282
Diffstat (limited to 'challenge-282/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-282/sgreen/python/ch-1.py | 30 |
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() |
