How to count near duplicates in a mixed pool using AnyDice?

Following on from this question: How to count duplicates in a mixed pool using AnyDice?

I’m also interested in the much harder question of using AnyDice to look at how much easier some dice mitigation of +/-1 makes getting duplicates (as per the example in that question).

For example, if I rolled 12, 12, 5, 4, 3, 1 the result of how many dice there are that are 1 away from a duplicate would be 3; because 5, 4 and 3 are all 1 away from another result.