Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created September 17, 2015 05:24
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/630f147dabd43ade43f2 to your computer and use it in GitHub Desktop.
Save anonymous/630f147dabd43ade43f2 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[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