Add group-by to utils.
* Applies a procedure to each element of a list and returns an association list mapping the procedures return value to a list of the elements that produce that return value.main
parent
25771dffeb
commit
5444c0654e
@ -1,6 +1,24 @@
|
|||||||
(use-modules (deliberate borda))
|
(use-modules (srfi srfi-1)
|
||||||
|
(deliberate borda))
|
||||||
|
|
||||||
(define alts '(bad best better good worst))
|
(define test-alts '("red" "green" "blue"))
|
||||||
(define p '(best better good))
|
|
||||||
|
|
||||||
(borda-score alts p)
|
(define test-pref '("blue"))
|
||||||
|
|
||||||
|
(define test-profile
|
||||||
|
'((1 . ("red" "green" "blue"))
|
||||||
|
(1 . ("green" "red" "blue"))
|
||||||
|
(1 . ("green"))
|
||||||
|
))
|
||||||
|
|
||||||
|
(borda-score test-alts test-pref)
|
||||||
|
|
||||||
|
(define (profile-borda-scores alternatives profile)
|
||||||
|
(apply append
|
||||||
|
(map (lambda (pair)
|
||||||
|
(borda-score alternatives (cdr pair)))
|
||||||
|
profile)))
|
||||||
|
|
||||||
|
(define test-scores (profile-borda-scores test-alts test-profile))
|
||||||
|
|
||||||
|
(define test-score-groups (group-by car test-scores))
|
||||||
|
Loading…
Reference in New Issue