brewersfan1976

is_sum_of_consecutive.rb

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