You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
764 B
Scheme

(define-module (deliberate borda)
#:export (borda-score))
(define (const-list length value)
(if (= length 0)
'()
(cons value (const-list (- length 1) value))))
(define (borda-score alternatives ranked)
;; Check whether all alternatives have been scored
(if (nil? alternatives)
'()
;; Check whether all ranked alternatives have been scored
(if (nil? ranked)
(let* ((n (length alternatives))
(score (/ (- n 1) 2)))
;; Assign average remaining score to all unranked alternatives
(map cons alternatives (const-list n score)))
;; Just use next rank
(let* ((alt (car ranked))
(remaining (delete alt alternatives)))
(cons (cons alt (length remaining))
(borda-score remaining (cdr ranked))))
)))