Re: begin traversal at the end of a list?
- From: Markus Triska <triska@xxxxxxxx>
- Date: Thu, 26 Apr 2007 02:13:40 +0200
student <nospam@xxxxxxxxxxx> writes:
write(NewBs),
get_single_char(Response),
more([Response]),nl,
!,
bell_triangle(NewBs).
By introducing an additional argument that is used to report solutions
incrementally, this kind of querying can be delegated to the toplevel:
aitken(R, R).
aitken(R0, R) :-
last(R0, L),
row(R0, L, R1),
aitken([L|R1], R).
row([], _, []).
row([A|As], B, [C|Cs]) :-
C is A + B,
row(As, C, Cs).
Example query:
%?- aitken([1], R).
%@ R = [1];
%@ R = [1, 2] ;
%@ R = [2, 3, 5] ;
%@ R = [5, 7, 10, 15] ;
%@ R = [15, 20, 27, 37, 52] a
%@ Yes
--
comp.lang.prolog FAQ: http://www.logic.at/prolog/faq/
.
- Follow-Ups:
- Re: begin traversal at the end of a list?
- From: student
- Re: begin traversal at the end of a list?
- References:
- Re: begin traversal at the end of a list?
- From: student
- Re: begin traversal at the end of a list?
- From: student
- Re: begin traversal at the end of a list?
- Prev by Date: Re: begin traversal at the end of a list?
- Next by Date: Re: begin traversal at the end of a list?
- Previous by thread: Re: begin traversal at the end of a list?
- Next by thread: Re: begin traversal at the end of a list?
- Index(es):
Relevant Pages
|
|