finish the function to calculate the length of shared border between neighbors