Skip to content

Instantly share code, notes, and snippets.

View Trimatix's full-sized avatar
🍂

Jasper Trimatix

🍂
  • Denmark
  • 09:12 (UTC +01:00)
View GitHub Profile
@Trimatix
Trimatix / python-naive-graph-colour-coding.py
Created August 30, 2025 10:54
Fixed length path finding in python with naive graph colour coding
"""
A naive implementation of graph colour coding: https://en.wikipedia.org/wiki/Color-coding
Inspired by this stack overflow answer by Julian "jubueche" Büchel: https://stackoverflow.com/a/45535671/11754606
This gist attempts to find a route of a given length, between two nodes in a graph.
This is a naive implementation that very often fails for route lengths near the maximum possible.
For example, a 22-node route between Talidor and Wah'Norr is possible, but often fails to be generated, even within 2000 graph colourations.
The approach is effectively a depth first search with stochastic constraints.
{"label":"test coverage","message":"91%","schemaVersion":1,"color":"hsl(109, 100%, 40%)"}
{"schemaVersion":1,"label":"test coverage","message":"83.35%","color":"green","namedLogo":"jest"}