Solve math puzzle