riddele_for_you,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.matrix input{
width: 20px;
margin: 5px;
}
</style>
</head>
<body>
<h2 style="text-align: center;">Решение методом Закревского</h2>
<div class="calc" id="frtabl">
Размер матрицы:
<select onchange="oms_mhwA(this.value)">
<option value="2" selected="selected">2×2</option>
<option value="3">3×3</option>
<option value="4">4×4</option>
<option value="5">5×5</option>
<option value="6">6×6</option>
<option value="7">7×7</option>
</select>
<p>Выберете размерность матрицы, после введите значения Матрицы A:</p>
</div>
<div class="matrix" oninput="createMatrix()"></div>
<div class="show"></div>
<button onclick="oms_zakra(createMatrix())">calc</button>
<script>
var num = 2;
function print(a, e, b) {
a = a.reduce(function(a, b) {
return a + "<div>" + JSON.stringify(b) + "</div>";
}, e);
document.querySelector(".show").innerHTML = a + b;
}
function oms_mhwA(el) {
num = el;
var matrix = document.querySelector(".matrix");
matrix.innerHTML = "";
for (var i = 0; i < el; i++) {
for (var k = 0; k < el; k++) {
matrix.innerHTML += '<input type="text" value="1">';
}
matrix.innerHTML += "<br>";
}
createMatrix();
}
function createMatrix() {
var el = num;
var matrix = [], inp = document.querySelectorAll(".matrix input");
for (var i = 0; i < inp.length; i++) {
if (!(i % el)) {
matrix.push([]);
}
matrix[i / el | 0].push(+inp[i].value);
}
print(matrix, "", "");
return matrix;
}
oms_mhwA(num)
function oms_zakra(m)
{
function s(a) {
return a.reduce(function (a, b) {
return a + b
}, 0)
}
function c(a) {
return a[0].reduce(function (e, b, g) {
e[g] = [];
for (b = 0; b < a.length; b++) e[g].push(a[b][g]);
return e
}, {})
}
function fn(a, e) {
return Object.keys(a).sort(function (b, g) {
return e ? s(a[g]) - s(a[b]) : s(a[b]) - s(a[g])
})[0]
}
function r(a, e) {
return e.reduce(function (b, e, h) {
e && (b[h] = a[h]);
return b
}, {})
}
function ff(a, e) {
return a.map(function (a) {
return a.filter(function (a, b) {
return 0 == e[b]
})
})
}
function print(a, e, b) {
a = a.reduce(function (a, b) {
return a + "<div>" + JSON.stringify(b) + "</div>"
}, e);
document.body.insertAdjacentHTML("beforeEnd", a + b)
}
var mat = m,
temp = "абвгдежзи".split("");
temp.length = m.length;
for (var res = []; m.length && m[0].length;) {
print(temp, "", "");
print(m, "", "");
var d = c(m),
n = fn(d),
t = d[n],
f = r(m, t),
k = fn(f, !0);
res.push(temp.splice(k, 1)[0]);
var v = m.splice(k, 1)[0];
m = ff(m, v)
}
print([res.sort()], "<b>", "</b>");
}
</script>
</body>
</html>