Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
"Skew-symmetric Matrix" solution in Clear category for [old] Skew-symmetric Matrix by day0ff
"use strict";
function symmetric(matrix) {
for(let row = 0; row < matrix.length; row++){
for(let col = row; col < matrix.length; col++){
if(matrix[row][col] + matrix[col][row] != 0) return false;
}
}
return true;
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(symmetric([
[0, 1, 2],
[-1, 0, 1],
[-2, -1, 0]]))
// These "asserts" using only for self-checking and not necessary for auto-testing
assert.equal(symmetric([
[0, 1, 2],
[-1, 0, 1],
[-2, -1, 0]]), true);
assert.equal(symmetric([
[0, 1, 2],
[-1, 1, 1],
[-2, -1, 0]]), false);
assert.equal(symmetric([
[0, 1, 2],
[-1, 0, 1],
[-3, -1, 0]]), false);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Oct. 11, 2018