/* Mosaic matrix (Rosetta code) in Picat. http://rosettacode.org/wiki/Mosaic_matrix """ Draw a 'mosaic' matrix which, for the purposes of this task, is a square matrix which has 1's in alternate cells (both horizontally and vertically) starting with a 1 in the top-left hand cell. Other cells can either be left blank or filled with some other character. If you can please use GUI """ E.g. 1 . 1 . 1 . 1 . 1 . . 1 . 1 . 1 . 1 . 1 1 . 1 . 1 . 1 . 1 . . 1 . 1 . 1 . 1 . 1 1 . 1 . 1 . 1 . 1 . . 1 . 1 . 1 . 1 . 1 1 . 1 . 1 . 1 . 1 . . 1 . 1 . 1 . 1 . 1 1 . 1 . 1 . 1 . 1 . . 1 . 1 . 1 . 1 . 1 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import v3_utils. import util. % import cp. main => go. go => N = 6, A = new_array(N,N), bind_vars(A,"."), foreach(I in 1..N) foreach(J in 1..N, I mod 2 == J mod 2) A[I,J] := "1" end, println(A[I].to_list.join(" ")) end, nl. go2 => N = 11, println([[cond(I mod 2 == J mod 2,"1",".") : J in 1..N].join() : I in 1..N].join("\n")), nl. % Shorter go3 => N=11,[[((1+I^J)/\1).to_string:J in 1..N].join:I in 1..N].join("\n").println. go4 => N = 11, println([[M:J in 1..N,m(I,J,M)].join() : I in 1..N].join("\n")), nl. go5 => N = 11, [[M:J in 1..N,m(I,J,M)].join() : I in 1..N].join("\n").println. m(A,B,"1"):-(A^B)/\1==0. m(_A,_B,".").