Solving algorithms with reduce