껍질 , 12 바이트
규칙 설명에 따라 11 바이트 또는 13 바이트 일 수 있습니다 .
±Λ=;1Ẋ×≈mηfT
온라인으로 사용해보십시오!
입력은 공백과 0 만 포함하는 행 목록입니다. 단일 문자열이 필요한 ¶경우 프로그램 앞에 추가 하여 행으로 분할하십시오. TIO 링크는 이미 명확성을 위해이 작업을 수행합니다. 출력은 0 또는 1입니다. 잘못된 값과 진실한 값이 ±있으면 제거 할 수 있습니다.
설명
±Λ=;1Ẋ×≈mηfT Implicit input: a list of lines.
T Transpose into list of columns.
m For each column,
ηf get list of indices of truthy elements.
In Husk, whitespace characters are falsy and other are truthy,
so this gets us the indices of 0s on each column.
Ẋ For each adjacent pair of these index lists,
× for all pairs drawn from the two lists,
≈ give 1 if they differ by at most 1, otherwise 0.
For each adjacent pair, this produces a list of 1s and 0s.
Λ Do all of these lists
=;1 equal [1]? Return either 0 or 30 (length of the outer list + 1).
± Signum; convert to 0 or 1.
아이디어는 ×≈(a) 모든 열에 정확히 하나의 0이 포함되고 (b) 그 위치가 최대 1만큼 달라 지도록하는 것입니다. 예를 들어, 8 열 입력을 고려하십시오.
0 0 0
000 0
00 0
먼저 mηfT인덱스 목록으로 변환
[[1],[2],[2,3],[1,2,3],[],[2],[1],[3]]
그런 다음 Ẋ×≈제공
[[1],[1,1],[1,1,0,1,1,1],[],[],[1],[0]]
각각 1최대 1만큼 다른 인덱스 쌍에 0해당하고 그렇지 않은 쌍에 해당합니다. [1]두 목록에 하나의 색인이 있고 색인이 최대 1 씩 다른 경우 각 결과는 정확하게 같습니다 .