home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / TESTS / LF / PROFILER.L00 < prev    next >
Text File  |  1996-06-04  |  632b  |  22 lines

  1. % Multiple each list element by F, up to a maximum of N.
  2. mult_list(F,N,[H|T]) ->
  3.         cond(R:(F*H) =< N, [R|mult_list(F,N,T)], []).
  4.  
  5. % Merge two lists of ascending integers.
  6. merge(L,[]) -> L.
  7. merge([],L) -> L.
  8. merge(L1:[H1|T1],L2:[H2|T2]) ->
  9.         cond(H1 =:= H2,
  10.              [H1|merge(T1,T2)],
  11.              cond(H1 > H2,
  12.                   [H2|merge(L1,T2)],
  13.                   [H1|merge(T1,L2)])).
  14.  
  15. % Generate the Hamming sequence from 1 to N.
  16. hamming_f(N) ->
  17.         S:[1|merge(mult_list(2,N,S),
  18.                    merge(mult_list(3,N,S),
  19.                          mult_list(5,N,S)))].
  20.  
  21. hamming :- write(hamming_f(1000)), nl.
  22.