1 ! Copyright (c) 2009 Aaron Schaefer. All rights reserved.
2 ! The contents of this file are licensed under the Simplified BSD License
3 ! A copy of the license is available at http://factorcode.org/license.txt
4 USING: arrays formatting io kernel math math.matrices
5 math.parser sequences ;
9 [ first2 ] dip '[ first2 [ _ * ] [ + ] bi* ] bi@ /i ;
17 : >matrix ( q s r t -- z )
18 [ 2array ] 2bi@ 2array ;
20 : produce ( z y -- z' )
21 [ 10 ] dip -10 * 0 1 >matrix swap mdot ;
23 : gen-x ( x -- matrix )
24 dup 2 * 1 + [ 2 * 0 ] keep >matrix ;
26 : consume ( z k -- z' )
29 :: (padded-total) ( row col -- str n format )
30 "" row col + "%" "s\t:%d\n"
31 10 col - number>string glue ;
33 : padded-total ( row col -- )
34 (padded-total) '[ _ printf ] call( str n -- ) ;
36 :: (pidigits) ( k z n row col -- )
41 row 10 + y "\t:%d\n%d" printf
42 k z y produce n 1 - row 10 + 1 (pidigits)
45 k z y produce n 1 - row col 1 + (pidigits)
48 k 1 + z k consume n row col (pidigits)
50 ] [ row col padded-total ] if ;
53 [ 1 { { 1 0 } { 0 1 } } ] dip 0 0 (pidigits) ;
55 : pidigits-benchmark ( -- )
58 MAIN: pidigits-benchmark