Sorry for the mess this code is, it's made of few hours and coffee (not the language, the drink, like https://www.pehub.com/wp-content/uploads/2013/05/cofee1-1024x682.jpg)
Some stuff could be muuuch more optimised, that's really not the point here! (I don't what the point it is, in fact x) )
That's a solver in JS for this problem:
http://www.lirmm.fr/~retore/projetsL2/projetLinPix.pdf
C'est un solveur en JavaScript pour ce problème :
http://www.lirmm.fr/~retore/projetsL2/projetLinPix.pdf
Try it online http://htmlpreview.github.io/?https://github.com/W95Psp/Link-A-Pix/blob/master/index.html