diff --git a/methods/schulzeResults.php b/methods/schulzeResults.php index ad91315..3dddc95 100644 --- a/methods/schulzeResults.php +++ b/methods/schulzeResults.php @@ -6,7 +6,7 @@ class schulze public int $ncandidats; public array $nvotes; - public $v = array( + public array $v = array( array(5, 1, 3, 2, 4), array(1, 5, 2, 4, 3), array(5, 3, 2, 4, 1), @@ -22,7 +22,7 @@ class schulze { for ($j=1;$j<=$ncandidats;$j++) { - void + void; } } } @@ -31,24 +31,30 @@ class schulze function test($v) { $w = array(); + $i = 0; + $j = 0; asort($v); print_r($v); - for($i=0;isset($v);$v++) + for($i = 0;$i < count($v) - 1;$i++) { + if ($i == 0) { - $w[] = $v[$i]; + + $w[$j]['vote'] = $v[$i]; + $w[$j]['n'] = 1; + $j += 1; } if ($v[$i] == $v[$i+1]) { - $w[$i] += 1; + $w[$J]["n"] += 1; }else { - $w[] = $v[$i+1]; + $w[$j++] = $v[$i+1]; } - print_r($w); } + print_r($w); } function result() diff --git a/test.php b/test.php index 0803b00..5ba71b3 100644 --- a/test.php +++ b/test.php @@ -2,7 +2,7 @@ require "methods/schulzeResults.php"; $vote = new schulze; - $vote->test(); + $vote->test($vote->v); ?>