smeghead #1369(2007/07/23 15:00 GMT) [ Common Lisp ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
(defstruct party vote (seat 0)) (defun max-index (lst) (let ((max 0) (max-index 0)) (loop for x in lst for i from 0 when (< max x) do (setf max-index i) (setf max x)) max-index)) (defun selection (parties) (let* ((selected (max-index (mapcar #'(lambda (x) (/ (party-vote x) (1+ (party-seat x)))) parties))) (selected-party (nth selected parties))) (setf (party-seat selected-party) (1+ (party-seat selected-party))) (loop for p in parties for i from 0 collect (if (eql i selected) selected-party p)))) (defun dhondt (n votes) (labels ((rec (n ps) (if (zerop n) ps (rec (1- n) (selection ps))))) (mapcar #'party-seat (rec n (mapcar #'(lambda (v) (make-party :vote v)) votes)))))
Rating0/0=0.00-0+
[ reply ]
smeghead
#1369()
[
Common Lisp
]
Rating0/0=0.00
(defstruct party vote (seat 0)) (defun max-index (lst) (let ((max 0) (max-index 0)) (loop for x in lst for i from 0 when (< max x) do (setf max-index i) (setf max x)) max-index)) (defun selection (parties) (let* ((selected (max-index (mapcar #'(lambda (x) (/ (party-vote x) (1+ (party-seat x)))) parties))) (selected-party (nth selected parties))) (setf (party-seat selected-party) (1+ (party-seat selected-party))) (loop for p in parties for i from 0 collect (if (eql i selected) selected-party p)))) (defun dhondt (n votes) (labels ((rec (n ps) (if (zerop n) ps (rec (1- n) (selection ps))))) (mapcar #'party-seat (rec n (mapcar #'(lambda (v) (make-party :vote v)) votes)))))Rating0/0=0.00-0+
[ reply ]