Code that "breaks" arduino

You will need to signal to the board how many conductors to test. In the event the operator leave the knob on two pin and puts a three pin cable on it would be an issue. That would lead back to using your arrangement of separate pins for each cable. But with some clever I/O management both can work.

There are 20 I/O pins on the UNO.

0-1: USB TX/RX

2: Pin 1 all cables
3: 2 pin cable pin 2
4-5: 3 pin cable pins 2-3
6-7-8: 4 pin cable pins 2-3-4

9: Pin 1 all cables
10-11: 2 pin cable pin 2
A0-A1: 3 pin cable pins 2-3
A2-A3-A4: 4 pin cable pins 2-3-4

LEDs on pins 12 and 1
A5-A6: Cable select 0-0=2 pin, 0-1=3 pin; 1-1=4 pin

You can read the analog pins using digitalRead(Ax)

As for the direction bperrybap is heading, instead of toggling the outputs HIGH and LOW using digitalWrite(x), change the the pinMode from INPUT_PULLUP (which becomes the high output) and OUTPUT (which becomes low output). As mentioned the advantage is the built-in current limiting.

Even if you don't test for the shorts, bperrybap comments have a good advantage for your setup.