Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One-liner solution in Uncategorized category for Skew-symmetric Matrix by nicuveo
def checkio(matr):
'return whether the specified square matrix is skew-symmetric or not'
h, w = len(matr), len(matr[0])
return all(matr[y][x] == -matr[x][y] for x in range(w) for y in range(h))
if __name__ == '__main__':
assert checkio([[0, 1,2],
[-1,0,1],
[-2,-1,0]]) == True, 'First'
assert checkio([[0, 1,2],
[-1,1,1],
[-2,-1,0]]) == False, 'Second'
assert checkio([[0, 1,2],
[-1,0,1],
[-3,-1,0]]) == False, 'Third'
print('All ok')
Nov. 9, 2012
Comments: