diff options
| author | Leo Manfredi <manfredi@cpan.org> | 2020-05-17 18:57:18 +0200 |
|---|---|---|
| committer | Leo Manfredi <manfredi@cpan.org> | 2020-05-17 18:57:18 +0200 |
| commit | 2c3618139717b4f7716ba4b96567b78c2c7920a2 (patch) | |
| tree | 4543857ead26920e4f84dfe794450ba87aa0a453 /challenge-060 | |
| parent | 9e6c712e010fc50a7842a0798521566bb7251a76 (diff) | |
| download | perlweeklychallenge-club-2c3618139717b4f7716ba4b96567b78c2c7920a2.tar.gz perlweeklychallenge-club-2c3618139717b4f7716ba4b96567b78c2c7920a2.tar.bz2 perlweeklychallenge-club-2c3618139717b4f7716ba4b96567b78c2c7920a2.zip | |
Solution Task #1 Python
Diffstat (limited to 'challenge-060')
| -rwxr-xr-x | challenge-060/manfredi/python/ch-1.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-060/manfredi/python/ch-1.py b/challenge-060/manfredi/python/ch-1.py new file mode 100755 index 0000000000..a430467f81 --- /dev/null +++ b/challenge-060/manfredi/python/ch-1.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +import re +import sys +from braceexpand import braceexpand + + +if len(sys.argv) != 2: + print("USAGE:\n\t %s { ABC | 123 }" % __file__) + sys.exit() + + +cols = [] +a = list(braceexpand('{A..Z}')) +b = list(braceexpand('{A..Z}{A..Z}')) +c = list(braceexpand('{A..Z}{A..Z}{A..Z}')) + +cols.extend(a) +cols.extend(b) +cols.extend(c) + +nums = [ n for n in range(1, len(cols) + 1) ] + +hcols = dict() +hnums = dict() + +for i in range(len(cols)): + hcols[ str(cols[i]) ] = nums[i] + hnums[ str(nums[i]) ] = cols[i] + + +pattern_nums = re.compile(r'^\d+$') +pattern_cols = re.compile(r'^[A-Z]{1,3}$') + +if pattern_nums.match(sys.argv[1]) and int(sys.argv[1]) <= len(nums): + print( hnums[ sys.argv[1] ] ) + +if pattern_cols.match(sys.argv[1]): + print( hcols[ sys.argv[1] ] ) + |
