교대 부호 행렬 인 n
의해 n
숫자로 이루어진 매트릭스 -1, 0, 1이되도록 :
- 각 행과 열의 합은 1
- 각 행과 열의 0이 아닌 항목은 대체 부호
이 행렬은 순열 행렬을 일반화하고 주어진 행렬의 수는 n
얼마 동안 관심 대상이었습니다. 그것들은 매트릭스 결정자를 계산하는 Dodgson 응축 방법 (Charles Dodgson, 더 잘 알려진 Lewis Carroll이라고 함) 중에 자연적으로 발생합니다.
다음은 4 x 4 개의 대체 부호 행렬에 대한 몇 가지 예입니다.
0 1 0 0 1 0 0 0 0 0 1 0 0 0 1 0
0 0 1 0 0 0 1 0 0 1 -1 1 1 0 -1 1
1 0 0 0 0 1 -1 1 1 -1 1 0 0 1 0 0
0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0
그리고 다음은 부호 행렬을 대체하지 않는 4 x 4 행렬의 예입니다.
0 1 0 0
0 0 0 1
1 0 0 0
0 0 1 -1 (last row and last column don't add to 1)
0 0 0 1
1 0 0 0
-1 1 1 0
1 0 0 0 (third row does not alternate correctly)
프로그램이나 함수가 부여된다 n
의해 n
매트릭스 ( n >= 1
출력 - -1s, 0과 1의) truthy 값 별도로 출력을, 지정된 행렬 교류 부호 행렬 인 경우 falsy 값.
이것은 code-golf 이므로 목표는 사용되는 바이트 수를 최소화하는 것입니다.
테스트 사례
다음 테스트 사례는 Python과 같은 2D 목록 형식으로 제공됩니다.
진실한 :
[[1]]
[[1,0],[0,1]]
[[0,1],[1,0]]
[[0,1,0],[0,0,1],[1,0,0]]
[[0,1,0],[1,-1,1],[0,1,0]]
[[0,1,0,0],[0,0,1,0],[1,0,0,0],[0,0,0,1]]
[[1,0,0,0],[0,0,1,0],[0,1,-1,1],[0,0,1,0]]
[[0,0,1,0],[0,1,-1,1],[1,-1,1,0],[0,1,0,0]]
[[0,0,1,0],[1,0,-1,1],[0,1,0,0],[0,0,1,0]]
[[0,0,1,0,0],[0,1,-1,1,0],[1,-1,1,0,0],[0,1,0,-1,1],[0,0,0,1,0]]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