Paste: matrix-nth and matrix-length
Author: | anatoo |
Mode: | factor |
Date: | Sun, 15 Feb 2009 20:24:31 |
Plain Text |
IN: ...
USING: math sequences kernel prettyprint ;
: matrix-nth ( n matrix -- elt )
[ first length [ rem ] [ /i ] 2bi ] keep nth nth ;
: matrix-length ( matrix -- n )
[ length ] [ first length * ] bi ;
{ { 3 4 }
{ 2 1 }
{ 5 7 }
{ 3 2 } } dup matrix-length [ swap matrix-nth . ] with each
Author: | slava |
Mode: | factor |
Date: | Mon, 16 Feb 2009 00:28:36 |
Plain Text |
anatoo: there is a /mod word you can use instead of [ rem ] [ /i ] 2bi.
Author: | anatoo |
Mode: | factor |
Date: | Mon, 16 Feb 2009 03:26:01 |
Plain Text |
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 ;
{ { 3 4 }
{ 2 1 }
{ 5 7 }
{ 3 2 } } dup matrix-length [ swap matrix-nth . ] with each
New Annotation