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

The following question provides a function that answers the question for a single kind of die; How do I count the number of duplicates in anydice?

I want to count how many duplicates there are in a mixed pool such as 3d12, 2d10, 1d8.

For example, if I rolled 12, 12, 3, 3, 3, 1 the result would be 5; because 5 of the dice have at least one other die that has rolled the same value.

I’m also interested in looking at how much easier some dice mitigation of +/-1 makes getting duplicates. This is probably a much harder 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.