What started as a friendly race between my friends and me to see who could crack each LinkedIn Zip puzzle the fastest quickly turned into a 3AM “there has to be a way to guarantee first place” experiment. That experiment became a fully automated solver powered by computer vision, Hamiltonian path algorithms, and mouse automation. It detects the puzzle, computes the optimal path, and completes it instantly, no human reflexes required!
- Hamiltonian Path Solver: Finds optimal path that traverses every node exactly once in the required order
- Automation: Draws solution automatically with the mouse controlled by the program
- Vision System: Detects board, cells, numbers (OCR Detection), and walls
pyautogui
opencv
pillow
numpy
Optional (for ocr)
pytesseract
FastestZipFinder/
├── main.py # Main integration script
├── vision.py # Board capture and detection
├── solver.py # Hamiltonian path solver
├── automation.py # Mouse control and drawing
├── README.md
- Captures a screenshot of a game board
- Detects grid structure by dividing board into cells
- Uses OCR to read numbers inside of cells
- Detects walls by identifying thick black lines
Uses a Hamiltonian Path Algorithm
- Hamiltonian path visits each cell exactly once
- Essentially DFS with following constraints:
- Must visit number nodes in order (1->2->3->...)
- Must visit ALL cells
- Cannot cross walls
- Must end at final node
Algorithm: Depth First Search with backtracking
- Start at node 1
- Visit each neighbour recursively
- Enforce node ordering (ie can't skip nodes)
- Backtrack if dead-end
- Time complexity: O(n!) in worst case, pruning helps
- Moves mouse to each cell position
- Holds left mouse button down
- Drags through the entire solution path
- Slight pause at each cell to ensure game registers it
py main.py-
Board Selection
- Position mouse at top-left corner
- Press Enter
- Position mouse at bottom right corner
- Press Enter
-
Grid Size
- Enter number of rows
- Enter number of columns
-
Number Detection
- OCR attempts automatic detection
- Falls back to manual input if needed
- Enter number for each cell (or enter to skip)
-
Wall Detection
- System automatically detects walls
- Fall back to manual input
- Wall is defined as two adjacent cells
-
Solving
- Algorithm finds Hamiltonian path
- Shows solution visualization
-
Automation
- Confirm you're ready
- Mouse automatically draws solution
- Move mouse to corner to abort (failsafe)
When prompted adjust:
- Drag speed:
0.05= fast,0.2= slow (how long to pause at each cell)
def find_hamiltonian_path(current, visited, path, next,_node_idx)
# Base case: visited all cells?
if len(visited) == total_cells:
if current == last_node:
return True # Solution found!
# Try each neighbor
for neighbor in get_neighbors(current):
if neighbor not in visited:
# Constraint: can't skip nodes
if neighbor is future_node and not next_node:
continue
# Explore
visited.add(neighbor)
if find_hamilton_path(neighbor, ...):
return True
visited.remove(neighbor) # Backtrack
return FalseOld Approach: Find seperate paths for each pair, and combine them
- Complex back tracking
- Multiple path conflicts
- Hard to ensure all cells filled
New Approach: One path through all cells
- Simpler algorithm
- Naturally fills all cells
- Fewer Conflicts
- Install Tesseract-OCR and pytesseract
- Use manual input fallback
- Ensure numbers are clearly visible
- Ensure game is clearly visible
- Use full screen or large window
- Good contrast between numbers and background
- Install Tesseract-OCR for better results
- Slow down drag speed (increase to 0.2-0.3)
- Be more precise when selecting board corners
- Ensure game window doesn't move
- Reduce grid size (smaller puzzles)
- Increase
max_pathslimit in solver - Use simpler puzzle first to test
- Reselect board area more carefully
- Make sure game window is stationary
- Check if cell size calculation is accurate
- Failsafe: Move mouse to screen corner to abort
- Preview mode: Visualize detection before solving
- Manual input: Always available if OCR fails
- Validation: Checks solution before drawing
- Grid must be rectangular (no irregular shapes)
- Walls must be thick black lines
- Requires Python 3.9+
- Automatic grid size detection
- Faster solving with better pruning
- Improved OCR detection
- Allows for removed cells
- Look into bit masking to improve time complexity
Educational project - use at your own risk. Not affiliated with LinkedIn.
Built using:
- OpenCV for computer vision
- PyAutoGUI for automation
- Tesseract for OCR
- NumPy for numerical operations
Improvements welcome! Focus areas:
- Better OCR accuracy
- Faster solving algorithm
- More robust wall detection
- UI improvements