Here's the code I'm using at the moment:
- Code: Select all
v=vector(#a * #b);
v[(i-1)*#b+j] = a[i] + b[j]
The code takes two vectors of arbitrary size and returns a sorted vector.
- Create a blank vector v to hold the elements.
- Assign to each vector element a sum
- Remove duplicates by casting to a set (slow: turns numbers to strings!)
- Cast from back to numeric form (slow)
- Sort the vector (relatively slow)