writeNum(0) :- !.
writeNum(N) :- write(N), nl, M is N-1, writeNum(M).

writeNum2(N) :- assert(n(N)), repeat, writeNum, retract(n(0)), !.
writeNum :- retract(n(M)), write(M), nl, L is M-1, assert(n(L)).

