aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/abigail/python/ch-1.py
blob: b9881895649cf060b5e2af3eeee906426184af4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/opt/local/bin/python

#
# See ../README.md
#

#
# Run as: python ch-1.py < input-file
#

import fileinput

def make_sequence (string, start):
    if string == start:
        return [start]

    if 0 == string . find (start):
        tail = string [len (start) :]
        result = make_sequence (tail, str (int (start) + 1)) or \
                 make_sequence (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_sequence (line, line [0 : i + 1])
        if result:
            print ("," . join (result))
            break