solves puzzle...needs recursion and refactoring