Skip to content
Snippets Groups Projects
Borda.go 693 B
Newer Older
package comsoc

Balthazar Wilson's avatar
Balthazar Wilson committed
import (
	"fmt"
)

func BordaSWF(p Profile) (count Count, err error) {
	count = make(Count)
Balthazar Wilson's avatar
Balthazar Wilson committed
	err = checkProfileFromProfile(p)
	if err != nil {
		return nil, err
	}
	nAlts := len(p[0])
	for _, row := range p {
		for i := 0; i < nAlts; i++ {
			count[row[i]] += nAlts - 1 - i
Balthazar Wilson's avatar
Balthazar Wilson committed
	return
}

func BordaSCF(p Profile) (bestAlts []Alternative, err error) {
	count, err := BordaSWF(p)
	if err != nil {
		return nil, err
	}
Balthazar Wilson's avatar
Balthazar Wilson committed
	return maxCount(count), err
}
Balthazar Wilson's avatar
Balthazar Wilson committed
func Test_borda() {
	profil := GenerateProfile(3, 5)
	fmt.Println("Profil :", profil)
Balthazar Wilson's avatar
Balthazar Wilson committed
	count, _ := BordaSWF(profil)
	fmt.Println("Décompte :", count)
Balthazar Wilson's avatar
Balthazar Wilson committed
	winners, _ := BordaSCF(profil)
	fmt.Println("Vainqueur(s) :", winners)