Advertisement
Guest User

Untitled

a guest
Sep 17th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. test_4 = [[1,2,3,4],[11,12,13,14],[21,22,23,24],[31,32,33,34]]
  2. test_3 = [[1,2,3],[4,5,6],[7,8,9]]
  3. test_result = [[1, 5, 9], [2, 6],[4,8], [3],[7]]
  4. def diags(a)
  5. ret = []
  6. size = a.size
  7. size.times{|z|
  8. x = []
  9. w = []
  10. (size-z).times{|y|
  11. x << a[y+z][y]
  12. w << a[z-y][z-y+1]
  13. }
  14. if z != 0
  15. ret << w
  16. end
  17. ret << x
  18.  
  19. }
  20. return ret
  21. end
  22.  
  23. puts "#{diags c}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement