Re: begin traversal at the end of a list?



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/
.



Relevant Pages

  • Query multiple records
    ... Tests/ Student ID, Test Name, Test Score, Test Date. ... In one to many relationships I have no idea how to find the one by querying the many related to it. ... EggHeadCafe - .NET Developer Portal of Choice ...
    (microsoft.public.access.queries)
  • Need Help
    ... For example I need to find each student who got above a certain score on 3 or more tests consecutively and within a certain time period. ... In one to many relationships I have no idea how to find the one by querying the many related to it. ... EggHeadCafe - .NET Developer Portal of Choice ...
    (microsoft.public.access.gettingstarted)
  • Query multiple records
    ... For example I need to find each student who got above a certain score on 3 or more tests consecutively and within a certain time period. ... In one to many relationships I have no idea how to find the one by querying the many related to it. ... EggHeadCafe - .NET Developer Portal of Choice ...
    (microsoft.public.access.gettingstarted)
  • Query multiple record
    ... For example I need to find each student who got above a certain score on 3 or more tests consecutively and within a certain time period. ... In one to many relationships I have no idea how to find the one by querying the many related to it. ... EggHeadCafe - .NET Developer Portal of Choice ...
    (microsoft.public.access.gettingstarted)