Here is an implementation from the great Simon Tatham's Portable Puzzle Collection:
https://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/gues...