wornsdorf algorithm implimentation