home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0963.lha / SIOD / scm / count-pairs.scm < prev    next >
Text File  |  1993-02-22  |  1KB  |  32 lines

  1. (define (count-pairs l)
  2.         (if (atom? l)
  3.             0
  4.             (+ 1 (count-pairs (car l))
  5.                  (count-pairs (cdr l)))))
  6.  
  7. (define (count-pairs-2 l s)
  8.         (cond ((atom? l) 0)
  9.               ((element-of-set? l s) 0)
  10.               (else (let ((s1 (adjoin-set l s)))
  11.                          (+ 1 (count-pairs-2 (car l) s1)
  12.                               (count-pairs-2 (cdr l) s1))))))
  13.  
  14. (define s the-empty-set)
  15.  
  16. (define (count-pairs-3 l)
  17.         (cond ((atom? l) 0)
  18.               ((element-of-set? l s) 0)
  19.               (else (set! s (adjoin-set l s))
  20.                     (+ 1 (count-pairs-3 (car l))
  21.                          (count-pairs-3 (cdr l))))))
  22.  
  23. (define (count-pairs-4 l)
  24.         (define n (empty-set))
  25.         (define (count l)
  26.                 (cond ((atom? l) 0)
  27.                       ((element-of-set? l n) 0)
  28.                       (else (adjoin-set! l n)
  29.                             (+ 1 (count (car l))
  30.                                  (count (cdr l))))))
  31.         (count l))
  32.