brewersfan1976

exercise_elaboration.rb

Jun 5th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.43 KB | None | 0 0
  1. def exerciseElaboration(p, n)
  2.     string = ""
  3.     string[0] = p.to_s
  4.    
  5.     x = 0
  6.     y = 1
  7.    
  8.     while (x < n)
  9.           string = string + "0"
  10.           x = x + 1
  11.     end
  12.    
  13.     string = string + p.to_s
  14.     squared = string.to_i ** 2
  15.     string = squared.to_s
  16.    
  17.     x = 0
  18.     sum = 0
  19.    
  20.     while (x < string.length)
  21.           sum = sum + string[x].to_i
  22.           x = x + 1
  23.     end
  24.    
  25.     return sum
  26. end
Advertisement
Add Comment
Please, Sign In to add comment