%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% chicken.pi %% http://users.ugent.be/~tschrijv/ppc/ppc2011_probs.pdf %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% main => test. test => chicken(5). chicken(N) => NR is 5+2*(N-1), NC is 7*2*(N-1)+6, A = new_array(NR,NC), place_u(A,2*(N-1)+1,1,N), (N mod 2=:=0->place_c2(A,1,7*(N-1)+1); place_c1(A,1,7*(N-1)+1)), place_d(A,3,7*(N-1)+7,N), foreach(R in 1..NR) foreach(C in 1..NC) (var(A[R,C])->print(" "); printf("%c",A[R,C])) end, nl end. place_u(_A,_R,_C,I), I=<1 => true. place_u(A,R,C,I) => place_cb(A,R,C), place_u(A,R-2,C+7,I-1). place_d(_A,_R,_C,I), I=<1 => true. place_d(A,R,C,I) => place_bc(A,R,C), place_d(A,R+2,C+7,I-1). place_c1(A,R,C) => place_s(A,R,C, " \\\\ "), place_s(A,R+1,C," (o>"), place_s(A,R+2,C,"\\\\_//)"), place_s(A,R+3,C," \\_/_)"), place_s(A,R+4,C,"___|__"). place_c2(A,R,C) => place_s(A,R,C, " // "), place_s(A,R+1,C," place_s(A,R,C, " \\\\ "), place_s(A,R+1,C," (o> "), place_s(A,R+2,C,"\\\\_//) "), place_s(A,R+3,C," \\_/_)|"), place_s(A,R+4,C,"___|__|"). place_bc(A,R,C) => place_s(A,R,C, " // "), place_s(A,R+1,C," true. place_s(A,R,C,[X|Xs]) => A[R,C] = X, place_s(A,R,C+1,Xs).