P
P
Pavel2020-03-04 20:20:57
.NET
Pavel, 2020-03-04 20:20:57

Can you help me find matrices?

A matrix A is called symmetric if the elements of row i + 1 are elements of row i with opposite order. An example of a symmetric matrix would be the following matrix

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Pogrebnyak, 2019-07-21
@Anton_repr

Regex.Replace(input, "<.*?>", String.Empty);

R
Roman, 2020-03-04
@Pavel13131313013

code (spoiler)
var matrixes =  [
  [
    [3, 2, 1],
    [1, 2, 3],
    [3, 1, 3]
  ], // Должен выводится 3
  [
    [3, 2, 1],
    [1, 2, 3],
    [3, 2, 1]
  ], // Должен выводится 0
  [
    [1, 0, 0, 0],
    [0, 1, 0, 0],
    [0, 0, 1, 0],
    [0, 0, 0, 1]
  ], // Должен выводится 4
  [
   [2, 4],
   [4, 2]
  ] // Должен выводится 0 
];

matrixes.forEach( matrix => {
   console.log("------------------------");
   console.table(matrix);
   console.log(calc(matrix));
});


function calc(matrix){
  let template = matrix[0];
  let result = matrix.reduce( (acc1, items, index1) => {
    if(index1===0) return acc1;
    template = template.reverse();
    acc1 += items.reduce( (acc2, item, index2) => {
        acc2 += Math.abs(template[index2]-item);
        return acc2;
    },0);
    return acc1;
  },0);
  return result;
}

result:
5e5fed549ce9e339758941.png
well, the sandbox:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question