%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% flag.pi
%%% by Neng-Fa Zhou, Salvador Abreu, and Ulrich Neumerkel
%%% http://cmpe.emu.edu.tr/bayram/courses/531/Prolog%20Competition/ppc2009.pdf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
main => test.
test => flag(5).
flag(N) =>
printf(" _\n (_)\n<___>\n"),
NR = 2*N+4,
NC = 5*N+5,
A = new_array(NR,NC),
p(A,1,5,N),
foreach(I in 1..NR)
A[I,2] = '|',
A[I,4] = '|',
foreach (J in 1..NC)
(var(A[I,J]) -> print(' ') ; print(A[I,J])),
(J == NC -> nl ; true )
end
end.
p(A,I,J,1) =>
foreach(C in 0..4)
A[I,J+C] = '_',
A[I+4,J+C] = '~'
end,
foreach(C in 1..3)
A[I+C,J+4] = '|'
end.
p(A,I,J,N) =>
foreach(C in 0..4) A[I,J+C] = '_' end,
foreach(C in 0..3) A[I+4,J+C] = '~' end,
A[I+1,J+5] = ')',
A[I+2,J+4] = '(',
A[I+3,J+4] = '|',
A[I+4,J+4] = '|',
A[I+5,J+4] = '|',
A[I+6,J+4] = '~',
p(A,I+2,J+5,N-1).