I don't have a clue about the equation to solve this but I managed to do it brute force with Python.

Code:

>>> import itertools
>>> couples = {0:1, 2:3, 4:5, 6:7}
>>> for k,v in couples.items():
couples[v] = k
>>> all_positions = list(itertools.permutations(range(8)))
>>> def is_valid(position):
if position[0] == couples[position[-1]]:
return False
for p in range(len(position) - 1):
if position[p] == couples[position[p+1]]:
return False
return True
>>> all_positions = [p for p in all_positions if is_valid(p)]
>>> len(all_positions)
11904
>>>

seems to be 11904