brewersfan1976

count_ways_to_change_digit.py

Sep 6th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. def countWaysToChangeDigit(value):
  2.     string = str(value)
  3.     string_length = len(string)
  4.     x = 0
  5.     y = 0
  6.     number = 0
  7.    
  8.     while (x < string_length):
  9.           while (y <= 9):
  10.                 string = string[:x] + str(y) + string[x + 1:]
  11.                
  12.                 if int(string) > value:
  13.                    number = number + 1
  14.                
  15.                 y = y + 1
  16.          
  17.           string = str(value)
  18.           x = x + 1
  19.           y = 0
  20.            
  21.     return number
Advertisement
Add Comment
Please, Sign In to add comment