Skip to content

Instantly share code, notes, and snippets.

Created September 17, 2015 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8b8b573fe1d5f34f3407 to your computer and use it in GitHub Desktop.
Save anonymous/8b8b573fe1d5f34f3407 to your computer and use it in GitHub Desktop.
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}"
@hemanth
Copy link

hemanth commented Sep 17, 2015

rb ftw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment