test_solve1(0,_) :- !.
test_solve1(N,H) :-
    time(N,Moves,solve1(H,Moves)),
    nl,
    N1 is N - 1,
    test_solve1(N1,H).

:- dynamic(hanoiDyn/5).

% --- hanoiDyn1(+NbOfDiscs, ?A, ?B, ?C, ?NbOfMoves).

hanoiDyn(1,_A,_B,_,1.0).                      %--- move _A to _B
hanoiDyn(N,A,B,C,Moves) :-
            N>1,
            N1 is N-1,
            hanoiDyn(N1,A,C,B,Moves1),        %--- move N-1 discs
            asserta((hanoiDyn(N1,A,C,B,Moves1) :-! )),

            hanoiDyn(N1,C,B,A,Moves2),        %--- move N-1 discs
            retract((hanoiDyn(N1,A,C,B,_     ) :-! )),
            Moves is Moves1 + Moves2 + 1.

solve1(N, Moves) :- 
	[A, B, C] = [a, b, c],          % L2
	hanoiDyn(N, A, B, C, Moves).    % L1

time(Text1,Text2,Goal) :-
    cpu_time(CPU),
    Goal,
    cpu_time(CPU2),
    CPUT is CPU2-CPU,
    tab(1), write(Text1), write(': ') ,write('nbrMoves = '),
    write(Text2),write('   '), write(CPUT), write('ms').
