[ create a new paste ] login | about

Link: http://codepad.org/4bWj9XMf    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Oct 11:
1
2
3
4
5
6
7
8
9
10
11
12
13
; find the minimum difference

(define (f xs ys)
  (let ((d (- (car xs) (car ys))))
    (let loop ((xs xs) (ys ys) (diff (abs d)))
      (cond ((or (null? xs) (null? ys)) diff)
            ((< (car xs) (car ys))
              (let ((d (- (car ys) (car xs))))
                (loop (cdr xs) ys (min d diff))))
            (else (let ((d (- (car xs) (car ys))))
                    (loop xs (cdr ys) (min d diff))))))))

(display (f '(19 22 24) '(37 38 49 88)))


Output:
1
13


Create a new paste based on this one


Comments: