brewersfan1976

is_sum_of_consecutive2.rb

Sep 25th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.43 KB | None | 0 0
  1. def isSumOfConsecutive2(n)
  2.     x = 1
  3.     y = 2
  4.     z = 0
  5.     number = 0
  6.    
  7.     while (x <= n)
  8.           z = x + y
  9.        
  10.           while (y <= n)
  11.                 if z == n then
  12.                    number = number + 1
  13.                 end
  14.                    
  15.                 y = y + 1
  16.                 z = z + y
  17.           end
  18.              
  19.           x = x + 1
  20.           y = x + 1
  21.     end
  22.        
  23.     return number
  24. end
Advertisement
Add Comment
Please, Sign In to add comment