From b9512bdf15f844141a2492c89c4d10c87d956caf Mon Sep 17 00:00:00 2001 From: OlgaSe Date: Tue, 22 Dec 2020 15:44:52 -0800 Subject: [PATCH] tests passed --- lib/hourglass.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/hourglass.rb b/lib/hourglass.rb index 4186b23..475fee6 100644 --- a/lib/hourglass.rb +++ b/lib/hourglass.rb @@ -1,4 +1,14 @@ def hourglass(matrix) - raise NotImplementedError, "The matrix method has not been implemented yet!" + sum = 0 + r = 0 + c = 0 + max_sum = -1.0/0.0 + 4.times do |r| + 4.times do |c| + sum = matrix[r][c] + matrix[r][c + 1] + matrix[r][c + 2] + matrix[r + 1][c + 1] + matrix[r + 2][c] + matrix[r + 2][c + 1] + matrix[r + 2][c+ 2] + max_sum = sum if max_sum < sum + end + end +return max_sum end \ No newline at end of file