Created
September 17, 2015 05:45
-
-
Save anonymous/8b8b573fe1d5f34f3407 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[y][z+y] | |
} | |
if z != 0 | |
ret << w | |
end | |
ret << x | |
} | |
return ret | |
end | |
puts "#{diags test_3}" | |
puts "#{diags test_3}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rb ftw