IN: ... USING: math sequences kernel prettyprint io ; : matrix-yx ( n matrix -- y x ) first length /mod ; : matrix-nth ( n matrix -- elt ) tuck matrix-yx spin nth nth ; : matrix-y ( n matrix -- y ) first length /i ; : matrix-x ( n matrix -- x ) first length rem ; : matrix-length ( matrix -- n ) [ length ] [ first length * ] bi ; ! example { { 3 4 } { 2 1 } { 5 7 } { 3 2 } } dup matrix-length [ swap matrix-nth . ] with each