aboutsummaryrefslogtreecommitdiff
path: root/challenge-200/sgreen/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-200/sgreen/python')
-rwxr-xr-xchallenge-200/sgreen/python/ch-1.py29
-rwxr-xr-xchallenge-200/sgreen/python/ch-2.py47
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])