aboutsummaryrefslogtreecommitdiff
path: root/challenge-102/abigail/python/ch-2.py
blob: e8c3ee71ec279754de2884dcf2ea32416f444620 (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
#!/opt/local/bin/python

#
# See ../README.md
#

#
# Run as python ch-2.py < input-file
#

import fileinput

#
# Working from the end of the required string backwards, we alternate
# placing a hash, and placing a number. We place them in an array @out,
# and at the end, print out said array in reverse order.
#
for index in fileinput . input ():
    index = int (index)
    out = []
    hash = 0
    while index > 0:
        hash = not hash
        if hash:
            out . append ("#")
            index = index - 1
        else:
            out . append (str (index + 1))
            index = index - len (str (index + 1))
    out . reverse ()
    print ("" . join (out))