
depth(M,X) :- member(X,M).

depth(M,X) :- write(M),nl,readln(_),
  member(A,M),
  member(B,M),
  New is A+B,
  depth([New|M],X).

% --------------------------------------------------------

depth2(M,X) :- member(X,M).

depth2(M,X) :- write(M),nl,readln(_),
  member(A,M),
  member(B,M),
  New is A+B,
  (member(New,M) -> NewM=M ; append(M,[New],NewM)),
  depth2(NewM,X).

% --------------------------------------------------------

iterative(M,X,_) :- member(X,M).

iterative(M,X,Depth) :- write(Depth-M),nl, %readln(_),
  Depth > 0,
  member(A,M),
  member(B,M),
  New is A+B,
  NewDepth is Depth-1,
  iterative([New|M],X,NewDepth).

% --------------------------------------------------------

x1 :- 
  statistics(runtime,[_,_]),
  iterative([2,4],11,5);statistics(runtime,[_,Time]),write(Time).

% --------------------------------------------------------

iterative2(M,X,_) :- member(X,M).

iterative2(M,X,Depth) :- write(Depth-M),nl, %readln(_),
  Depth > 0,
  member(A,M),
  member(B,M),
  New is A+B,
  \+ member(New,M),
  sort([New|M],NewM),
  \+ gabsSchon(NewM),
  assert(gabsSchon(NewM)),
  NewDepth is Depth-1,
  iterative2([New|M],X,NewDepth).

% --------------------------------------------------------

x2 :- 
  statistics(runtime,[_,_]),
  iterative2([2,4],11,6);statistics(runtime,[_,Time]),write(Time).

x22 :- 
  statistics(runtime,[_,_]),
  iterative2([2,4],11,7);statistics(runtime,[_,Time]),write(Time).

% --------------------------------------------------------

breadth(M,X,D) :- 
  member(X,M),
  length(M,L),write(D-L-M).

breadth(M,X,Depth) :- Depth1 is Depth+1, write(Depth-M),nl, %readln(_),
  findall(New, ( member(A,M),
                 member(B,M),
                 New is A+B, New < Depth*100
               ),
          AllNew),
  append(M,AllNew,M2),
  sort(M2,M3),
  breadth(M3,X,Depth1).
