-
-
Save anonymous/630f147dabd43ade43f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_4 = [[1,2,3,4],[11,12,13,14],[21,22,23,24],[31,32,33,34]] | |
test_3 = [[1,2,3],[4,5,6],[7,8,9]] | |
test_result = [[1, 5, 9], [2, 6],[4,8], [3],[7]] | |
def diags(a) | |
ret = [] | |
size = a.size | |
size.times{|z| | |
x = [] | |
w = [] | |
(size-z).times{|y| | |
x << a[y+z][y] | |
w << a[z-y][z-y+1] | |
} | |
if z != 0 | |
ret << w | |
end | |
ret << x | |
} | |
return ret | |
end | |
puts "#{diags c}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment