1 ! Copyright (c) 2012 Anonymous
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io kernel math math.parser math.ranges sequences ;
4 IN: rosetta-code.multiplication-tables
6 ! http://rosettacode.org/wiki/Multiplication_tables
8 ! Produce a formatted 12×12 multiplication table of the kind
9 ! memorised by rote when in primary school.
11 ! Only print the top half triangle of products.
14 [ number>string 2 CHAR: space pad-head write " |" write ]
15 [ 1 - [ " " write ] times ]
18 [ * number>string 4 CHAR: space pad-head write ] with each
23 1 12 [a,b] [ number>string 4 CHAR: space pad-head write ] each nl
25 12 [ "----" write ] times nl
26 1 12 [a,b] [ print-row ] each ;