home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 02a / pctj1186.zip / REVERSE.PRO < prev    next >
Text File  |  1986-09-19  |  763b  |  23 lines

  1. /* Number of logical inferences = (N**2 + N)/2 + N + 1,  */
  2. /* where N is the number of elements in the list.        */
  3. /* In this case N = 256, so there are 33,153 inferences. */
  4.  
  5. reverse([],[]).
  6. reverse([X|Y],Z) :- reverse(Y,Y1), append(Y1,[X],Z).
  7.  
  8. append([],X,X).
  9. append([X|Y],Z,[X|W]) :- append(Y,Z,W).
  10.  
  11. /* Generate a 256-element list and then reverse it       */
  12.  
  13. test :- write('Generating test data...'), nl,
  14.         List8 = [aa,bb,cc,dd,ee,ff,gg,hh],
  15.         append(List8,List8,List16),
  16.         append(List16,List16,List32),
  17.         append(List32,List32,List64),
  18.         append(List64,List64,List128),
  19.         append(List128,List128,List256),
  20.         write('Start...'), nl,
  21.         reverse(List256,Result),
  22.         write(Result), nl.
  23.