/* Multiplication tables (Rosetta code) in Picat. http://rosettacode.org/wiki/Multiplication_tables This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. go => N=12, make_table(N), nl. % % Make a table of size N % make_table(N) => printf(" "), foreach(I in 1..N) printf("%4w", I) end, nl, println(['-' : _ in 1..(N+1)*4+1]), foreach(I in 1..N) printf("%2d | ", I), foreach(J in 1..N) if J>=I then printf("%4w", I*J) else printf(" ") end end, nl end, nl. % As a "one-liner" go2 => N = 12, ((" " ++[ to_fstring("%3w", I) : I in 1..N].join(' ')) ++ "\n" ++ ['-' : _ in 1..(N+1)*4] ++ "\n" ++ [ [to_fstring("%4w",cond(J>=I,I*J,'')) : J in 1..N ].join('') ++ " |" ++ to_fstring("%2d",I) :I in 1..N].join("\n")).println().