Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
No x-skew-ses solution in Uncategorized category for Skew-symmetric Matrix by HeNeArKr
def checkio(matrix):
size = len(matrix)
# Look for simplest failure first: non-zero diagonal
if any(x != 0 for x in [matrix[r][r] for r in range(size)]):
return False
# Check elements above diagonal for a_ij = -a_ji condition
for r in range(size-1):
for c in range(r+1, size):
if matrix[r][c] != -matrix[c][r]:
return False
return True
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio([
[0, 1, 2],
[-1, 0, 1],
[-2, -1, 0]]) == True, "1st example"
assert checkio([
[0, 1, 2],
[-1, 1, 1],
[-2, -1, 0]]) == False, "2nd example"
assert checkio([
[0, 1, 2],
[-1, 0, 1],
[-3, -1, 0]]) == False, "3rd example"
May 21, 2016
Comments: