Solution of Keitai

Keitai can be solved by generating all possible solutions and then counting them. Basically, we need to add exactly one digit to any valid position in the original number. This method grants one possible number at a time, not necessarily unique. After having generated all numbers, the duplicates can be easily erased, using a specialized data structure (C++'s set or Python's set).

    1 def solve(s):
    2     possible = []
    3 
    4     for pos in range(2, 10):
    5         for digit in range(0, 10):
    6             new = s[:pos] + str(digit) + s[pos:]
    7             possible.append(new)
    8 
    9     return len(set(possible))
   10 
   11 print solve(raw_input())

At a closer look, we start to notice that the code above outputs 73 for any given input. This is due to the fact that Keitai is not an input-dependant problem. In order to see why, try to simulate (on a piece of paper) the process described, for a shorter input number.

For all the tractor fans:

    1 print 73
Questions?

Sponsors Gold