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

#
# See ../README.md
#

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

import fileinput

for line in fileinput . input ():
    result = 0
    seen_one = False
    for digit in list (line . strip ()):
        result = result * 9
        if seen_one:
            result = result + 8
        elif digit == "1":
            seen_one = True
        elif digit != "0":
            result = result + int (digit) - 1
    print (result)