algorithm to solve the Wolf Goose and the Corn Problem