diff options
| author | boblied <boblied@gmail.com> | 2023-01-23 08:29:56 -0600 |
|---|---|---|
| committer | boblied <boblied@gmail.com> | 2023-01-23 08:29:56 -0600 |
| commit | c2de8f565b88096181337a6e2890c7ca4b6a6e9e (patch) | |
| tree | 2a692c38c3d7d3a842ecefd526dab448af534f66 /challenge-200/sgreen/python | |
| parent | 109bfa578eb7dad7db280313e577f9ce3659175f (diff) | |
| parent | 27b88f614b9bb53872ef0da19a56087505836db0 (diff) | |
| download | perlweeklychallenge-club-c2de8f565b88096181337a6e2890c7ca4b6a6e9e.tar.gz perlweeklychallenge-club-c2de8f565b88096181337a6e2890c7ca4b6a6e9e.tar.bz2 perlweeklychallenge-club-c2de8f565b88096181337a6e2890c7ca4b6a6e9e.zip | |
Merge branch 'master' of https://github.com/boblied/perlweeklychallenge-club
Diffstat (limited to 'challenge-200/sgreen/python')
| -rwxr-xr-x | challenge-200/sgreen/python/ch-1.py | 29 | ||||
| -rwxr-xr-x | challenge-200/sgreen/python/ch-2.py | 47 |
2 files changed, 76 insertions, 0 deletions
diff --git a/challenge-200/sgreen/python/ch-1.py b/challenge-200/sgreen/python/ch-1.py new file mode 100755 index 0000000000..0d65c06fad --- /dev/null +++ b/challenge-200/sgreen/python/ch-1.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import sys + + +def main(n): + solutions = [] + + for start in range(len(n)-2): + # Calculate the difference between the first two values + diff = abs(n[start] - n[start+1]) + + for end in range(start+2, len(n)): + if abs(n[end] - n[end-1]) == diff: + # We have a solution + solutions.append(tuple(n[start:end+1])) + else: + break + + if solutions: + print(*solutions, sep=', ') + else: + print('()') + + +if __name__ == '__main__': + # Turn the strings into integers + n = [int(i) for i in sys.argv[1:]] + main(n) diff --git a/challenge-200/sgreen/python/ch-2.py b/challenge-200/sgreen/python/ch-2.py new file mode 100755 index 0000000000..593c4589ae --- /dev/null +++ b/challenge-200/sgreen/python/ch-2.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import sys + + +def print_row(line, numbers): + row = [] + + for n in numbers: + if type(line) == str: + # We want to show a solid line + if line in n: + row.append('-------') + else: + row.append(' ') + else: + # We have a left side and right side + left = '|' if line[0] in n else ' ' + right = '|' if line[1] in n else ' ' + row.append(f'{left} {right}') + + print(*row, sep=' ') + + +def main(n): + # Turn the numbers into a list of strings to show + truth = 'abcdef bc abdeg abcdg bcfg acdfg acdefg abc abcdefg abcfg'.split( + ' ') + numbers = [truth[int(i)] for i in n] + + # Define the lines we want to show + lines = [ + 'a', + ['f', 'b'], + ['f', 'b'], + 'g', + ['e', 'c'], + ['e', 'c'], + 'd' + ] + + for line in lines: + print_row(line, numbers) + + +if __name__ == '__main__': + main(sys.argv[1]) |
