このディレクトリの索引
http://pc12.2ch.net/test/read.cgi/tech/1235561034/658
#
#  -1 
#  ---3 
#  ------6 
#  ----------10 
#  ---------------15 
#  ---------------------21 
#  -------------------------25 
#  ---------------------------27 
#  ---------------------------27 
#  -------------------------25 
#  ---------------------21 
#  ---------------15 
#  ----------10 
#  ------6 
#  ---3 
#  -1 
# 

pro_658(Max,M) :-
    f1(0,Max,M,0).

f1(Max,Max,M,V) :- f2(Max,M,V).
f1(N,Max,M,V) :-
    N =< Max,
    V2 is V + N + 1,
    'print-'(V2),
    N2 is N + 1,
    f1(N2,Max,M,V2),
    'print-'(V2).

f2(N,M,_) :- N =< M,!.
f2(N,M,V) :-
    V2 is V + N - M,
    'print-'(V2),
    N2 is N - M,
    f2(N2,M,V2),
    'print-'(V2).

'print-'(V) :-
    for(1,N,V),
    write(-),
    N=V,
    write_formatted('%t\n',[V]).