brewersfan1976

crossing_sum.rb

Oct 16th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.34 KB | None | 0 0
  1. def crossingSum(matrix, a, b)
  2.     sum = 0
  3.     i = 0
  4.    
  5.     while (i < matrix[0].length)
  6.           sum = sum + matrix[a][i]
  7.           i = i + 1
  8.     end
  9.    
  10.     j = 0
  11.    
  12.     while (j < matrix.length)
  13.           sum = sum + matrix[j][b]
  14.           j = j + 1
  15.     end
  16.    
  17.     sum = sum - matrix[a][b]
  18.    
  19.     return sum
  20. end
Advertisement
Add Comment
Please, Sign In to add comment