aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/abigail/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-116/abigail/python')
-rw-r--r--challenge-116/abigail/python/ch-1.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-116/abigail/python/ch-1.py b/challenge-116/abigail/python/ch-1.py
new file mode 100644
index 0000000000..795d4ecabd
--- /dev/null
+++ b/challenge-116/abigail/python/ch-1.py
@@ -0,0 +1,33 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+
+def make_chain (string, start):
+ if string == start:
+ return [start]
+
+ if 0 == string . find (start):
+ tail = string [len (start) :]
+ result = make_chain (tail, str (int (start) + 1)) or \
+ make_chain (tail, str (int (start) - 1))
+ if result:
+ return [start] + result
+
+ return None
+
+
+for line in fileinput . input ():
+ line = line . strip ()
+ for i in range (0, len (line)):
+ result = make_chain (line, line [0 : i + 1])
+ if result:
+ print ("," . join (result))
+ break