A design procedure for sum and difference patterns by means of reactive sorting algorithms