; Program: A Pile Splitting Problem ; Solution: Originally written by Max Hailperin; modified by ; Bill Marion (2/10/06) ; ; Statement of the Problem: Given n objects in a pile (n >= 1), ; split the pile into two smaller piles. Continue to split each ; pile into two smaller piles until there are n piles of size one. ; At each splitting compute the sum of reciprocals of the size of the two ; smaller piles. Once there are n piles, the product of all the sums of the ; reciprocals is computed. The result will always be the same no matter how ; each of the piles is split into two smaller piles. The product of the sums of ; the reciprocals is a function of n. (Rosen K., 2003; Tanton, J. 2004) ; This computational process allows the user repeatedly to input the number ; of objects in the pile, n, (0 to quit), and, if n >= 1, calls the function ; to compute the product of the sums of the reciprocals and displays that product. (define pile-splitting-3 (lambda () (newline) (display "Enter the number of objects in the pile--or 0 to quit") (newline) (let ((n (read))) (if (= n 0) (begin (newline) (display "finished") (newline)) (if (= n 1) (begin (newline) (display "The product of the sums of the reciprocals is: ") (display 0) (newline) (pile-splitting-3)) (begin (let ((ProductofSumRecip (products-of-sum-of-reciprocals n))) (newline) (display "The product of the sums of the reciprocals is: ") (display ProductOfSumRecip) (newline)) (pile-splitting-3))))))) ; This computational process generates a recursive process and splits ; the piles randomly into k and n-k piles until there are n piles of ; size 1. Then, the product of the sums of the reciprocals is computed. (define products-of-sum-of-reciprocals ; generates a recursive process and (lambda (n) ; splits randomly (into k and n-k) (if (= n 1) 1 (let ((k (+ 1 (random (- n 1))))) (* (+ (/ 1 k) (/ 1 (- n k))) (products-of-sum-of-reciprocals k) (products-of-sum-of-reciprocals (- n k)))))))