JavaScript
var matrix = [
[ 1, 2, 0, 3, 4, 0, 2 ],
[ 0, 4, 0, 0, 7, 0, 4 ],
[ 5, 6, 7, 8, 0, 1, 0 ],
[ 1, 0, 0, 0, 4, 0, 0 ],
[ 0, 4, 0, 0, 7, 2, 4 ],
[ 5, 0, 0, 0, 0, 3, 0 ],
[ 0, 0, 0, 0, 4, 9, 3 ],
];
answers = {}
window.onload = function() {
var html = "", tab;
html += "<pre>" + matrix.map(function(row) { return row.join() }).join("\n") + "</pre>"
for(var name in answers) {
tab = answers[name](matrix)
html += "<h1>" + name + "</h1>\n";
html += "<table border=1 cellpadding=5 cellspacing=0>\n"
html += tab
html += "</table>"
html += "<pre>" + tab.replace(/<\/td>/g, "$&\n").replace(/</g, "<") + "</pre>\n"
html += "<hr>"
}
document.body.innerHTML = html
}
////////////////////////////////////////////////////////////////////////////
answers['Christian Landgren'] = function(matrix) {
var table = matrix.reduce(function(rows, row){
rows.push(row.reduce(function(newRow, col){
var lastCol = newRow[newRow.length - 1];
if (!col && lastCol) {
lastCol.colspan = (lastCol.colspan || 1) + 1;
} else if (!col && !lastCol) {
var lastRowCol = rows[rows.length-1][newRow.length];
if (lastRowCol) lastRowCol.rowspan = (lastRowCol.rowspan || 1) + 1;
} else {
newRow.push({value:col});
}
return newRow;
}, []));
return rows;
}, []);
return table.map(function(row) {
return "<tr>" + row.map(function(c) {
var s = "";
if(c.colspan)
s += " colspan=" + c.colspan;
if(c.rowspan)
s += " rowspan=" + c.rowspan;
return "<td" + s + ">" + c.value + "</td>";
}).join("") + "</tr>";
}).join("")
}
answers['XiozZe'] = function(Omatrix) {
var matrix = []
for (var i = 0; i < Omatrix.length; i++){
matrix[i] = Omatrix[i].slice(0);
}
...