1
0
This commit is contained in:
Daniel Tartavel 2022-09-23 20:18:54 +02:00
parent bd977181e0
commit cf94d99129

View File

@ -33,19 +33,17 @@ class schulze
$r = array(); $r = array();
foreach($votes as $vote) foreach($votes as $vote)
{ {
$r[] = implode($vote); $r[] = implode("/", $vote);
} }
return $r; return $r;
} }
function votify($votes) function votify(&$votes)
{ {
$r = array();
foreach($votes as $vote) foreach($votes as $vote)
{ {
$r[] = explode($vote); $vote["vote"] = explode("/", $vote["vote"]);
} }
return $r;
} }
function test($v) function test($v)
@ -58,21 +56,17 @@ class schulze
print_r($v); print_r($v);
for($i = 0;$i < count($v) - 1;$i++) for($i = 0;$i < count($v) - 1;$i++)
{ {
$s = $v[$i];
if ($i == 0) if ($i == 0)
{ {
$w[$j]["vote"] = $v[$i]; $w[$s] = 1;
$w[$j]["n"] = 1;
$j += 1;
} }
if ($v[$i] === $v[$i+1]) if ($s == $v[$i+1])
{ {
$x = array_search($v[$i], $w); $w[$s] += 1;
$w[$x]["n"] += 1;
}else }else
{ {
$w[$j]["vote"] = $v[$i+1]; $w[$s] = 1;
$w[$j]["n"] = 1;
$j += 1;
} }
} }
$w = votify($w); $w = votify($w);