Logic working

Solves the puzzle, functionality for printing out the solution will be
given soon.