Ahh, så var jeg godt nok tæt på i min egen algoritmejagt - but no cigar.
- har så prøvet at gøre den hjemmebane/udebane retfgærdig..
Ikke 100% perfekt - men det snerper
Prøv selv at tilføje/fjerne hold...
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Kampsystem</title><style type="text/css">
td {text-align:center;font:10pt Trebuchet MS,Arial;}
</style><script>
var hold = new Array( //"0","1","2","3","4","5","6","7" )
"Arsenal"
,"Leeds"
,"Vojens"
,"Vejle"
,"Inter"
,"Roma"
,"Nivå"
,"OB"
,"Lem"
)
if (hold.length / 2 != parseInt(hold.length / 2)) // ulige
hold[ hold.length ] = "_" // lige!
var HU = new Array()
for (var i=0;i<hold.length;i++)
HU[ hold[i] ] = hold[i]+"|"
function roter() // 01234567 > 07123456 > 06712345 > 05671234 ...
{
var tmp = hold[ hold.length-1 ]
for (var i=hold.length-1; i>1; i--) hold[ i ] = hold[ i-1 ]
hold[ 1 ] = tmp
}
function huttelihut( s ) // holdnavn:HUUHHUHUHUHHHU
{
var t = s.substring(0,s.indexOf("|")+1)
var s = s.substring(s.indexOf("|")+1)
var tmp=s
var h=0;var u=0
for (var i=0;i<s.length;i++)
if (s.substring(i,i+1) == "H")
h++
else
u++
t += h+" hjemme, "+u+" ude"
if (h>u)
t += " "+(h-u)
else if (h<u)
t += " "+(h-u)
return t
}
function roundRobin() // 0 1 2 3 kamp=lodret par
{ // 7 6 5 4
var tabel = "<table border='1' cellpadding='4' cellspacing='10'><tr>"
var prik = "v"
udeBane = true
for (var i=1; i<hold.length; i++)
{
tabel += "<td><table border='0'><tr><td colspan='3'>Kamp "+(i)+"<hr></td></tr>";
sidderOver = ""
for (var n=0; n<hold.length/2; n++)
{
if (hold[n] == "_" || hold[hold.length-1-n] == "_")
if (hold[n] == "_")
sidderOver = hold[hold.length-1-n]
else
sidderOver = hold[n]
else
{
if (udeBane)
{
udeBane = !udeBane
tabel += "<tr><td style='text-align:right;'>" + hold[n] + "</td>"+
"<td style='padding:0 6px;color:red;'>"+prik+"</td>" +
"<td style='text-align:left;'>" + hold[hold.length-1-n] +"</td></tr>"
HU[ hold[n] ] += "H"
HU[ hold[hold.length-1-n] ] += "U"
}
else
{
tabel += "<tr><td style='text-align:right;'>" + hold[hold.length-1-n] + "</td>"+
"<td style='padding:0 6px;color:red;'>"+prik+"</td>" +
"<td style='text-align:left;'>" + hold[n] +"</td></tr>"
HU[ hold[n] ] += "U"
HU[ hold[hold.length-1-n] ] += "H"
}
}
}
if (i/2 == parseInt(i/2))
udeBane = !udeBane
if (sidderOver != "")
tabel += "<tr><td colspan='3'><hr><b>"+sidderOver+"</b></td></tr>"
tabel += "</table></td>"
roter()
}
tabel += "</tr></table><p>"
roter() // tilbage til start
tabel += "<table cellpadding='4'>"
for (i=0;i<hold.length;i++)
if (hold[i] != "_")
tabel += "<td style='text-align:right;'>"+huttelihut(HU[ hold[i] ]).replace("|",":</td><td style='text-align:left;'>")+"<tr>"
tabel += "</table>"
document.getElementById("show").innerHTML = tabel
}
</script></head><body onload="roundRobin()">
<div id="show"></div>
</body>