
:- dynamic(count/1).
:- dynamic(count_mod/1).

count(0).

count_mod(0).

run :-
        repeat,
        count(N0),
        retract(count(_)),
        (   N0 =:= 10000 ->
            assertz(count(0)),
            count_mod(M0),
            retract(count_mod(_)),
            M1 is M0 + 1,
            assertz(count_mod(M1)),
            format("~w.\n", [M0])
        ;   N1 is N0 + 1,
            assertz(count(N1))
        ),
        read(Ls),
        (   nonvar(Ls), fd_all_different(Ls) ->
            true
        ;   portray_clause(false-Ls), halt
        ),
        false.

:- initialization(run).