I have a square matrix. Let's say that I set it to 3 and put as data 1 to 9, the corners would be 1, 3, 7, 9.
So, I use this code to find and add them:
for i in 0..N-1
for j in 0..N-1
if(((i==0) || (i==N-1))&&((j==0) || (j==N-1)))
E[i]=(M[i][j])
sumaE+=E[i].to_i
end
end
end
print("Esquinas:#{E}.\nSuma=#{sumaE}")
It works because it gives me the sum as 20, but the array gives it incomplete ["1", nil, "9"].
Does anyone know how to solve nil
?
(Extra data: I think my ruby is 2.2)