brewersfan1976

count_ways_to_change_digit.rb

Aug 14th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.53 KB | None | 0 0
  1. def countWaysToChangeDigit(value)
  2.     string = value.to_s
  3.     string_length = string.length
  4.     x = 0
  5.     y = 0
  6.     ways = 0
  7.    
  8.     while (x < string_length)
  9.           while (y <= 9)
  10.                 string[x] = y.to_s
  11.              
  12.                 if string.to_i > value then
  13.                    ways = ways + 1
  14.                 end
  15.                    
  16.                 y = y + 1
  17.           end
  18.              
  19.           y = 0
  20.           x = x + 1
  21.           string = value.to_s
  22.     end
  23.        
  24.     return ways
  25.    
  26. end
Advertisement
Add Comment
Please, Sign In to add comment