Python 3, 457 316 306 bytes
E=enumerate
V={'+'}
Q=[[(-j,i,k)for i,u in E(open(0))for j,v in E(u)for k in[{v}&V,'join'][u[j:j+2]=='|-']]]
while Q:
a,b,c,d,*e=A=tuple(x//2for y,x in sorted((y,x)for x,y in E(Q.pop())));e or exit('NOT')
if{A}-V:V|={A};Q+=[[c,d,a,b]+e,A,A[2:]+A[:2]][a<c<b<d:][c<a<d<b:]
if b==d:Q=[[a,c]+e]
exit('KNOT')
¿Eh?
El programa primero convierte el nudo en un diagrama rectangular, que tiene las siguientes restricciones:
- No hay dos segmentos verticales u horizontales en la misma línea.
- Ningún segmento vertical cruza sobre un segmento horizontal.
Por ejemplo, el primer caso de prueba se convierte al siguiente diagrama rectangular:
+-----------+
| |
| | +-------+
| | | |
| +-------+ | | |
| | | | | |
| | +---+ | |
| | | | | |
| | | +---+ |
| | | |
| | | +-------+
| | | | | |
+-----+ | | | |
| | | | | |
| +---+ | | |
| | | | | |
| | +-------------+ | |
| | | | | |
| | | +---+ |
| | | | | |
| | | | +---+
| | | |
+-+ | |
| |
+-+
que representamos únicamente por la secuencia de coordenadas y de los segmentos verticales, de derecha a izquierda:
(5,10, 1,9, 8,10, 9,12, 5,12, 1,4, 0,3, 2,4, 3,7, 6,8, 7,11, 2,11, 0,6)
Luego busca simplificaciones del diagrama rectangular como se describe en Ivan Dynnikov, “Presentaciones en arco de enlaces. Simplificación monotónica ”, 2004 . Dynnikov demostró que, desde cualquier diagrama rectangular del nudo, hay una secuencia de movimientos simplificadores que termina en el diagrama trivial. Brevemente, los movimientos permitidos incluyen:
- Permutando cíclicamente los segmentos verticales (u horizontales);
- Intercambiando segmentos verticales (u horizontales) consecutivos bajo ciertas restricciones de configuración.
- Reemplazar tres vértices adyacentes que se encuentran en la esquina del diagrama con un vértice.
Vea el periódico para fotos. Este no es un teorema obvio; no se mantiene si, por ejemplo, se utilizan movimientos Reidemeister que no aumentan el número de cruces. Pero para los tipos particulares de simplificaciones anteriores, resulta ser cierto.
(Simplificamos la implementación solo permutando segmentos verticales, pero también permitiendo que todo el nudo se transponga para intercambiar horizontalmente con vertical).
Manifestación
$ python3 knot.py <<EOF
+-------+ +-------+
| | | |
| +---|----+ +-------+
| | | | | |
+-------|------------|---+
| | | |
+---+ +---+
EOF
KNOT
$ python3 knot.py <<EOF
+----------+
| |
| +--------------+
| | | |
| | +-|----+ |
| | | | | |
| +-----+ | |
| | | |
| +------|---+
| |
+---------------+
EOF
NOT
$ python3 knot.py <<EOF # the Culprit
+-----+
| |
+-----------+ |
| | | |
| +-+ | +---|-+
| | | | | | | |
| +-|-------+ | |
| | | | | | | |
+-|-+ | | +---+ |
| | | |
+---|---------+
| |
+-+
EOF
NOT
$ python3 knot.py <<EOF # Ochiai unknot
+-----+
| |
+-|---------+
| | | |
| | +-+ | |
| | | | | |
+-|-|---|-|-+ |
| | | | | | | |
| | | +---|---+
| | | | | |
+-------+ | |
| | | |
| +-------+
| |
+-------+
EOF
NOT
$ python3 knot.py <<EOF # Ochiai unknot plus trefoil
+-----+ +-----+
| | | |
+-|---------+ |
| | | | | |
| | +-+ | +---+ |
| | | | | | | |
+-|-|---|-|-+ +---+
| | | | | | | |
| | | +---|-----+
| | | | | |
+-------+ | |
| | | |
| +-------+
| |
+-------+
EOF
KNOT
$ python3 knot.py <<EOF # Thistlethwaite unknot
+---------+
| |
+---+ +---------+
| | | | | |
| +-------+ | |
| | | | | |
| | | +---+ |
| | | | | |
| | +-------+ |
| | | | | |
| +-------+ | |
| | | | | |
+-----------+ | | | |
| | | | | |
| +-----------+ | | |
| | | | | |
| | +-------------+ |
| | | |
| | +-----+
| | | |
| | +---+
| | | |
+---------------------+ |
| |
+---------------------+
EOF
NOT
$ python3 knot.py <<EOF # (−3,5,7)-pretzel knot
+-------------+
| |
+-|-----+ |
| | | |
+-|-+ +-------+ |
| | | | | |
+-|-+ +---+ +---+
| | | | | |
| | +---+ +---+
| | | | | |
| | +---+ +---+
| | | | | |
| +---+ +---+
| | | |
| | +---+
| | | |
| | +---+
| | | |
| +---+
| |
+-----+
EOF
KNOT
$ python3 knot.py <<EOF # Gordian unknot
+-------------+ +-------------+
| | | |
| +---------+ | | +---------+ |
| | | | | | | |
| | +-------------+ +-------------+ | |
| | | | | | | | | | | |
| | | +---------+ | | +---------+ | | |
| | | | | | | | | | | | | | | |
| +-------+ | +-------+ +-------+ | +-------+ |
| | | | | | | | | | | | | | | |
+-------+ | +-------+ | | +-------+ | +-------+
| | | | | | | | | | | | | | | |
| +-------+ | | | | | | | | +-------+ |
| | | | | | | | | | | | | | | |
+-------+ | | | | | | | | | | +-------+
| | | | | | | | | | | | | | | |
| +-----+ | | | | | | +-----+ |
| | | | | | | | | | | |
+---------+ | | | | +---------+
| | | | | | | |
+---------+ | | +---------+
| | | | | | | |
| | +-----------------+ | |
| | | | | |
| +---------------------+ |
| | | |
+-----------+ +-----------+
EOF
NOT