Skip to content

Instantly share code, notes, and snippets.

@OisinMoran
Created April 2, 2020 22:45
Show Gist options
  • Save OisinMoran/cbc1736789d7559a401818f4961b507c to your computer and use it in GitHub Desktop.
Save OisinMoran/cbc1736789d7559a401818f4961b507c to your computer and use it in GitHub Desktop.
from itertools import permutations
import networkx as nx
import matplotlib.pyplot as plt
def flips(x):
for idx, (a, b) in enumerate(zip(x[:-1], x[1:])):
yield x[:idx] + (b,) + (a,) + x[idx+2:]
G = nx.Graph()
for perm in permutations(range(4)):
for flipped in flips(perm):
G.add_edge(perm, flipped)
nx.draw(G, with_labels=True)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment