;;; shuffle: combine two lists by taking alternate elements from ;;; the given lists ;;; John David Stone ;;; Department of Mathematics and Computer Science ;;; Grinnell College ;;; stone@cs.grinnell.edu ;;; created February 2, 2000 ;;; last revised February 2, 2000 ;;; Givens: ;;; LEFT and RIGHT, both lists. ;;; Result: ;;; SHUFFLED, a list. ;;; Preconditions: ;;; None. ;;; Postconditions: ;;; Let |LEFT| and |RIGHT| be the lengths of LEFT and RIGHT, ;;; respectively, and let z be the lesser of |LEFT| and |RIGHT|. ;;; (1) The length of SHUFFLED is |LEFT| + |RIGHT|. ;;; (2) For every natural number k less than z, the element at ;;; position 2k of SHUFFLED is the element at position k of ;;; LEFT, and the element at position 2k + 1 of SHUFFLED is ;;; the element at position k of RIGHT. ;;; (3) For every natural number k greater than or equal to z and ;;; less than the greater of |LEFT| and |RIGHT|, the element at ;;; position 2z + k of SHUFFLED is the element at position ;;; z + k of LEFT or of RIGHT, whichever is longer. (define shuffle (lambda (left right) (cond ((null? left) right) ((null? right) left) (else (cons (car left) (cons (car right) (shuffle (cdr left) (cdr right))))))))