Created
June 6, 2011 09:59
-
-
Save shirok/1010022 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (count xs) | |
(if (or (null? xs) | |
(null? (cdr xs))) | |
0 | |
(let ([minimum (apply min xs)]) | |
(cond | |
[(= minimum (first xs)) (count (cdr xs))] | |
[(= minimum (last xs)) (+ 1 (count (cdr (reverse xs))))] | |
[else (let loop ([L '()] [R xs]) | |
(if (= minimum (car R)) | |
(+ 2 (count (append (cdr R) L))) | |
(loop (cons (car R) L) (cdr R))))])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment