Ok, here we go:
Okay, this is an interesting case.
A boxed game that comes with a download game instead of a Switch game card is something that should be counted as a digital game, because it's the game card that constitutes physical ownership of a game. I'll have to add that to the OP because I forgot about that lame practice of selling boxes with download codes. Thinking further about this, there are scummy practices where only a part of a game is on the game card and the rest needs to be downloaded. Those games I'd count as physical because a game card exists.
If you own a game in both physical and digital format - like in your example because of a gift - then each copy counts as one game.
So in the sum, you own 17 third party games of which 4 are physical and 13 are digital. The box that came with a download code counts as 0 physical/1 digital whereas your duplicate counts as 1 physical/1 digital. Does that make sense?