Python 3, 457 316 306 byte
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')
Hah?
Program pertama kali mengkonversi simpul ke diagram persegi panjang, yang memiliki batasan sebagai berikut:
- Tidak ada dua segmen vertikal atau horizontal terletak pada garis yang sama.
- Tidak ada segmen vertikal yang melewati segmen horizontal.
Misalnya, test case pertama dikonversi ke diagram persegi panjang berikut:
+-----------+
| |
| | +-------+
| | | |
| +-------+ | | |
| | | | | |
| | +---+ | |
| | | | | |
| | | +---+ |
| | | |
| | | +-------+
| | | | | |
+-----+ | | | |
| | | | | |
| +---+ | | |
| | | | | |
| | +-------------+ | |
| | | | | |
| | | +---+ |
| | | | | |
| | | | +---+
| | | |
+-+ | |
| |
+-+
yang kami wakili secara unik oleh urutan koordinat y dari segmen vertikal, dari kanan ke kiri:
(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)
Kemudian mencari penyederhanaan diagram segi empat seperti yang dijelaskan dalam Ivan Dynnikov, “Arc-presentations of links. Penyederhanaan monotonik ”, 2004 . Dynnikov membuktikan bahwa dari diagram persegi panjang unknot, ada urutan langkah penyederhanaan yang berakhir pada diagram sepele. Secara singkat, gerakan yang diizinkan meliputi:
- Secara manual mengubah segmen vertikal (atau horizontal);
- Bertukar segmen vertikal (atau horizontal) berurutan di bawah batasan konfigurasi tertentu.
- Mengganti tiga simpul yang berdekatan yang terletak di sudut diagram dengan satu simpul.
Lihat kertas untuk gambar. Ini bukan teorema yang jelas; itu tidak berlaku jika, katakanlah, Reidemeister bergerak yang tidak menambah jumlah penyeberangan yang digunakan sebagai gantinya. Tetapi untuk jenis penyederhanaan tertentu di atas, ternyata benar.
(Kami menyederhanakan implementasinya dengan hanya mengijinkan segmen vertikal, tetapi juga memungkinkan seluruh simpul dialihkan ke interchange horizontal dengan vertikal.)
Demo
$ 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