brewersfan1976

digit_distance_number.rb

Jun 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.25 KB | None | 0 0
  1. def digitDistanceNumber(n)
  2.     x = 1
  3.     string = n.to_s
  4.     output = ""
  5.    
  6.     while (x < string.length)
  7.           output = output + ((string[x].to_i - string[x - 1].to_i).abs).to_s
  8.           x = x + 1
  9.     end
  10.    
  11.     return output.to_i
  12. end
Advertisement
Add Comment
Please, Sign In to add comment