Initial code for borda method code.

main
Edward L Platt 2 years ago
parent 688f1d0989
commit a1d393c582

@ -0,0 +1,24 @@
(define-module (deliberation 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))))
)))

@ -0,0 +1,6 @@
(use-modules (borda))
(define alts '(bad best better good worst))
(define p '(best better good))
(borda-score alts p)
Loading…
Cancel
Save