For the n+1 cart, it was always the smallest diff between n and any remaining carts.
Picking the first n, was more difficult. A strong hint was if the ROM name contained a variant of the word Japan. Otherwise, imagine you had 4 images, you could diff them 16 ways, but half of those ways are mirror images of each other ie. a diff of ROM 2->4 is the inverse of of a diff of ROM 4->2.
So ideally, the first ancestor would be the image with the most amount of the smallest children.
Brute force compare all the ROMs to each other and find "ancestor" with the least amount of changes as compared to any other.
Pick that as an ancestor, re-brute force check every remaining ROM against that one for changes.
It was silly and wasteful computationally but you could store 40 variations of a cart in 50MB instead of 1GB.