HW6 Solutions Solution to Scoring Bridge Hands Project: (define (card-val card) (cond ((equal? (bf card) 'a) 4) ((equal? (bf card) 'k) 3) ((equal? (bf card) 'q) 2) ((equal? (bf card) 'j) 1) (else 0))) (define (high-card-points hand) (accumulate + (every card-val hand))) (define (count-suit suit hand) (count (keep (lambda (card) (equal? (first card) suit)) hand))) Thinking about domain and range really helps in this problem; there are many ways to get confused about what to use as argument to which helper function. In particular, it's important to distinguish among the data types suit, card, and hand. (define (suit-counts hand) (every (lambda (suit) (count-suit suit hand)) '(s h c d))) This solution is not obvious, because the second argument to EVERY is a constant, rather than one of the original arguments. Students may find it easier to understand this less elegant alternative: (define (suit-counts hand) (se (count-suit 's hand) (count-suit 'h hand) (count-suit 'c hand) (count-suit 'd hand))) (define (suit-dist-points n) (if (<= n 2) (- 3 n) 0)) or, the slightly less elegant way: (define (suit-dist-points n) (cond ((= n 0) 3) ((= n 1) 2) ((= n 2) 1) (else 0))) (define (hand-dist-points hand) (accumulate + (every suit-dist-points (suit-counts hand)))) (define (bridge-val hand) (+ (high-card-points hand) (hand-dist-points hand)))