NeuralThink: Learning Algorithms For Consistent and Efficient Extrapolation Across General Tasks