; nuts and bolts

(define (biggest bolts nuts)
  ; assume there exists exactly one bolt bitter than all nuts
  (if (null? bolts) #f
    (let loop ((bolts (cdr bolts)) (nuts nuts) (biggest (car bolts)))
      (cond ((null? nuts) biggest)
            ((<= (car nuts) biggest)
              (loop bolts (cdr nuts) biggest))
            ((null? bolts) #f)
            (else (loop (cdr bolts) nuts (car bolts)))))))

(display (biggest '() '())) (newline)
(display (biggest '() '(4))) (newline)
(display (biggest '(4) '())) (newline)
(display (biggest '(1 4 2) '(3))) (newline)
(display (biggest '(7 8 9) '(5))) (newline)
(display (biggest '(1 2 3) '(5))) (newline)