home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix CD 2.0
/
Phoenix_CD.cdr
/
02a
/
pctj1186.zip
/
REVERSE.PRO
< prev
next >
Wrap
Text File
|
1986-09-19
|
763b
|
23 lines
/* Number of logical inferences = (N**2 + N)/2 + N + 1, */
/* where N is the number of elements in the list. */
/* In this case N = 256, so there are 33,153 inferences. */
reverse([],[]).
reverse([X|Y],Z) :- reverse(Y,Y1), append(Y1,[X],Z).
append([],X,X).
append([X|Y],Z,[X|W]) :- append(Y,Z,W).
/* Generate a 256-element list and then reverse it */
test :- write('Generating test data...'), nl,
List8 = [aa,bb,cc,dd,ee,ff,gg,hh],
append(List8,List8,List16),
append(List16,List16,List32),
append(List32,List32,List64),
append(List64,List64,List128),
append(List128,List128,List256),
write('Start...'), nl,
reverse(List256,Result),
write(Result), nl.