[racket] syntax, differently
1 minutes, 3 alpha renamings, one line break, and two cuts in extremely verbose English, et voil`a, it fits:
;; <NOT TELLING OTHERS> : state -> (listof state)
;; all possible successor states that can be reached in one boat crossing
(define (compute-possible-states state)
(local [;; how-many : symbol bl -> number
;; to find out how many s are in a bl
(define (how-many s bl)
(cond [(empty? bl) 0]
[else (cond [(symbol=? s (first bl))
(+ 1 (how-many s (rest bl)))]
[else (how-many s (rest bl))])]))
;; possible-states accumulate all the possible (incorrect) future
;; boat loads, given the current state.
(define (compute-a boat-loads possible-states)
(cond [(empty? boat-loads) possible-states]
[else
(local [(define num-mis (how-many 'M (first boat-loads)))
(define num-can (how-many 'C (first boat-loads)))
(define (new-state op1 op2 boat-posn)
(make-state (op1 (state-ml state) num-mis)
(op1 (state-cl state) num-can)
(op2 (state-mr state) num-mis)
(op2 (state-cr state) num-can)
boat-posn))
(define logical-boat-move
(cond [(symbol=? (state-boat-posn state) 'left)
(new-state - + 'right)]
[else (new-state + - 'left)]))]
(compute-a (rest boat-loads)
(cons logical-boat-move possible-states)))]))]
(compute-a BOAT-LOADS empty)))