I added another array, of the same size as the array of routes. The second array simply flagged whether the route had visited a lower case cave. It should have been a quick change, but I made a syntax error that wasn't flagged as such
if (a == 1);
{
b = 2;
}
when I should have written:-
if (a == 1)
{
b = 2;
}
Once I had sorted that, it took me ages to spot that I hadn't deleted an entry to the second array at the same place where I deleted an entry to the main array.