xmas(N) :- tree(0, N, L, []), string_to_list(S, L), write(S). tree(N, N) --> { S is N * 2 + 4 }, "o", repeat("-", S), "o". tree(0, N0) --> { maplist(plus(0), [0,2,4], [S1,S2,S3]) }, { maplist(plus(N0), [2,1,0], [P1,P2,P3]) }, { N1 is 1 }, repeat(" ", P1), "/", repeat(" ", S1), "\\", "\n", repeat(" ", P2), "/", repeat(" ", S2), "\\", "\n", repeat(" ", P3), "/", repeat(" ", S3), "\\", "\n", tree(N1, N0), "\n", { P4 is N0 + 2}, repeat(" ", P4), "||". tree(N, N0) --> { N < N0 }, { S is N0 - N - 1 }, { S0 is N * 2 }, { N1 is N + 1 }, { maplist(plus(S0), [0,2,4], [S1,S2,S3]) }, { maplist(plus(S), [1,2,1], [P1,P2,P3]) }, repeat(" ", P1), "o-/", repeat(" ", S1), "\\-o", "\n", repeat(" ", P2), "/", repeat(" ", S2), "\\", "\n", repeat(" ", P3), "/", repeat(" ", S3), "\\", "\n", tree(N1, N0), "\n", { P4 is N0 + 2}, repeat(" ", P4), "||". repeat(_, 0) --> []. repeat(C, N) --> { N > 0 }, C, { N1 is N - 1 }, repeat(C, N1).