Implement Untangle Puzzle Game Logic
Problem Implement the logic behind the Untangle puzzle. Nodes sit at arbitrary 2D coordinates and are joined by edges that may visually cross. Determine which edges cross, support repositioning a node to a new coordinate, and re-check whether the graph is untangled (zero crossings).
Input / Output
- Input: a list of node coordinates, a list of edges given as node-index pairs, and a stream of move operations (node id -> new coordinate).
- Output: after each move, the set of crossing edge pairs — or simply whether the puzzle is now solved.
Constraints
- Edges that share an endpoint touch at that endpoint but must NOT count as crossing. This is the case that breaks naive implementations.
- Collinear and overlapping segments need a defined answer, as does a node dropped exactly onto an existing edge.
- Moves are interactive, so per-move work must be far cheaper than recomputing every pair from scratch.
- Coordinates may be integers, in which case the geometric test can stay exact.
Example
- Nodes A=(0,0), B=(2,2), C=(0,2), D=(2,0), with edges A-B and C-D: they cross at (1,1) -> tangled. Moving D to (0,3) removes the crossing -> solved.
- Edges A-B and B-C share endpoint B: they meet, but the puzzle still counts as solved — reporting this pair is the classic bug.
asked …