well, since gen/1 should generate the integers from 0 to 5 (technically, if it was integers bellow 5 we should produce negatives too) you can just do:
gen(0).
gen(1).
gen(2).
gen(3).
gen(4).
gen(5).
which technically fulfils chack's restrictions xD
for a predicate gen/2 in which the first argument defines the max number we can do:
gen(N,R):-
N>0,
R is N-1.
gen(N,R):-
N>1,
NN is N-1,
gen(NN,R).
but this has the advantage of using the first argument. a rephrase of the rules to avoid the first solution would be that we should be able to replace every occurrence of 5 with some other number without changing the rules and the program should still work; we should also add that we cannot use lists (unless they have exactly 1 element) or tupples or basically any term with two variables as argument as well as any kind of encoding (2^X * 3*Y for example). Inspired by the first program:
gen(X):-
clause(g(_),_) ->
g(X) ; (generate(5),!, g(X)).
generate(-1):-
compile_predicates([g/1]).
generate(N):-
assert(g(N)),
NN is N-1,
generate(NN).
compile_predicates/1 is just for the speed improvement; note that if we change the max number we should restart the VM. another option would be to avoid compiling g/1 and add a retract_all(g(_)) before we call generate/1. Of course the obvious problem is that it's not pure prolog since we rely on meta-predicates.
well, with all these restrictions it appears impossible indeed