create a hash to hold processed pairs, with a key like "3 4" to indicate that 3 has been processed against 4 get minimum and maximum key values (3 & 11 in this case) loop from minimum to maximum minus interval if interval contains more than one item for each pair of items in interval check hash to see if the pair has been processed if not process the pair mark the pair in the hash