From 5ca5b1d170f591341b15a45d8d6e122f9fcfe219 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Thu, 15 Nov 2018 18:10:49 -0800 Subject: [PATCH 1/2] tests pass --- lib/matrix_check_sum.rb | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/matrix_check_sum.rb b/lib/matrix_check_sum.rb index dc2a66b..03fa45e 100644 --- a/lib/matrix_check_sum.rb +++ b/lib/matrix_check_sum.rb @@ -2,6 +2,45 @@ # whether the sum of each row matches the sum of corresponding column i.e. sum # of numbers in row i is the same as the sum of numbers in column i for i = 0 to row.length-1 # If this is the case, return true. Otherwise, return false. + +require 'pry' def matrix_check_sum(matrix) - raise NotImplementedError + i = 0 + matrix_len = matrix.length #rows + + + # len = matrix_len.dup + + matrix_len.times do + + c_sum = 0 + r_sum = 0 + j = 0 + + row_len = matrix[i].length + # + # len2 = row_len.dup + + row_len.times do + + + if matrix[j][i] != nil + c_sum += matrix[j][i] + end + + if matrix[i][j] != nil + r_sum += matrix[i][j] + end + + j+= 1 + end + + if c_sum != r_sum + return false + end + + i += 1 + end + + return true end From 5da13b1d5f4741d0e301f60f1841e96668e63a8e Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 1 Dec 2018 19:51:56 -0800 Subject: [PATCH 2/2] cleanup --- lib/matrix_check_sum.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/matrix_check_sum.rb b/lib/matrix_check_sum.rb index 03fa45e..7a3ed5c 100644 --- a/lib/matrix_check_sum.rb +++ b/lib/matrix_check_sum.rb @@ -8,9 +8,6 @@ def matrix_check_sum(matrix) i = 0 matrix_len = matrix.length #rows - - # len = matrix_len.dup - matrix_len.times do c_sum = 0 @@ -18,8 +15,6 @@ def matrix_check_sum(matrix) j = 0 row_len = matrix[i].length - # - # len2 = row_len.dup row_len.times do