/* Flag problem in Picat. From "How to Solve it With B-Prolog?" http://www.cs.nmsu.edu/ALP/2010/08/how-to-solve-it-with-b-prolog/ (Prolog Programming Contest 2010) """ The Prolog Programming Contest flag grows bigger with every edition. Here are those for the first, second and third edition: _ _ _ (_) (_) (_) <___> <___> <___> | |_____ | |_____ | |_____ | | | | | ) | | ) | | | | | (_____ | | (_____ | | | | | | | | | | ) | |~~~~~ | |~~~~| | | |~~~~| (_____ | | | | | | | | | | | | | ~~~~~~ | | ~~~~~| | | | | | | | | | ~~~~~~ | | Write a general flag/1 predicate that generates the flag for any edition N on the screen by the goal ?-flag(N). Do not add extra spaces to the left! """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => go. go => flag(3), flag(4), flag(5), nl. 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] = "|" end, foreach(I in 1..NR, J in 1..NC) Aij = A[I,J], (var(Aij) -> printf(" ") ; printf(Aij)), (J == NC -> nl ; true ) 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] ="~", In = I + 2, Jn = J + 5, Nn = N - 1, p(A,In,Jn,Nn).