# Two-Colour Zig-Zag Numberlink on Rectangles: A Forbidden-Pattern Characterization, a Constructive Polynomial-Time Algorithm, and a Lean Verification

DevFeed: [Two-Colour Zig-Zag Numberlink on Rectangles: A Forbidden-Pattern Characterization, a Constructive Polynomial-Time Algorithm, and a Lean Verification](<https://devfeed.tech/articles/two-colour-zig-zag-numberlink-on-rectangles-a-forbidden-pattern-characterization-a-constructive-polynomial-time-algorithm-and-a-lean-verification-108572.md>)

Original publisher: [Read original article](<https://arxiv.org/abs/2610.37691>)

Author: Zzyv Zzyzek

Published: 2026-10-30T04:00:00Z

Content type: article

Language: en

Sources: [arXiv: Machine Learning](<https://devfeed.tech/sources/arxiv-machine-learning.md>)

Topics: [Lean](<https://devfeed.tech/topics/lean.md>), [Algorithms](<https://devfeed.tech/topics/algorithms.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [c](<https://devfeed.tech/tags/c.md>), [characterization](<https://devfeed.tech/tags/characterization.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [cs-ds](<https://devfeed.tech/tags/cs-ds.md>), [cs-lg](<https://devfeed.tech/tags/cs-lg.md>), [dynamic-programming](<https://devfeed.tech/tags/dynamic-programming.md>), [graphs](<https://devfeed.tech/tags/graphs.md>), [grid](<https://devfeed.tech/tags/grid.md>), [hamiltonian](<https://devfeed.tech/tags/hamiltonian.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [lean](<https://devfeed.tech/tags/lean.md>), [lean-4](<https://devfeed.tech/tags/lean-4.md>), [patterns](<https://devfeed.tech/tags/patterns.md>), [python](<https://devfeed.tech/tags/python.md>), [verification](<https://devfeed.tech/tags/verification.md>)

## AI overview

The paper characterizes two-pair Zig-Zag Numberlink on rectangles with endpoints anywhere in the grid. When both sides are at least 11, an instance is solvable exactly when it avoids a finite forbidden-pattern catalogue covering parity, border alternation, local corner and edge cases, 65 corner configurations, and forced-route propagation. If either side is at most 10, frontier dynamic programming decides solvability in time linear in the longer side. For solvable instances, a constructive method deletes empty lines, splits by straight cuts, and splices pieces back together in O((R+C)RC) time. Lean 4 verifies the characterization and dynamic-programming correctness; finite checks use native decide. The abstract also reports Python, JavaScript, and C implementations with identical output.

## Source excerpt

arXiv:2610.37691v1 Announce Type: cross Abstract: In Zig-Zag Numberlink, pairs of endpoints in a grid must be joined by vertex-disjoint paths that together visit every cell. The problem is NP-complete when the number of pairs is un- bounded (Adcock et al.). For a single pair it is the Hamiltonian path problem in rectangular grid graphs, solved by Itai, Papadimitriou and Szwarcfiter. Two pairs on a rectangle form the paired 2-disjoint path cover problem. We settle the case of two pairs on rectangles with the endpoints anywhere in the grid. If both sides of the rectangle are at least 11, an instance is solvable if and only if no entry of a finite catalogue of forbidden patterns occurs. The catalogue consists of a parity condition, an alternation condition on the border, a handful of local corner and edge patterns, 65 listed corner configurations, and a rule that propagates forced routes out of the corners before testing alternation. If a side is at most 10, a frontier dynamic programming algorithm decides the instance in time linear in the long side. The characterization is construc- tive. Solutions are built by deleting empty lines, splitting the rectangle by straight cuts, and splicing the pieces back together, in time O((R+C) RC). Both directions of the characterization and the correctness of the dynamic programming algorithm are verified in Lean 4. The finite case analyses, which are window certificates for the corner configurations and a check of all irreducible instances with sides 11-22, are carried out by the Lean compiler via native decide. We describe the algorithm, the catalogue, the proof structure, the compromises made in the formalization, and implementations in Python, JavaScript and C that produce identical output.