#!/usr/bin/env python3 # Enumerate all possible combinations of faces and check if valid from itertools import combinations combs = [(0, 1), (0, 4), (0, 6), (1, 6), (1, 8), (2, 5), (3, 6), (4, 6)] def main(): c = 0 cubes = list(combinations(list(range(7))+list(range(6,9)), 6)) for i,a in enumerate(cubes): for b in cubes[i+1:]: c += conds(a, b) return c def conds(a, b): def sym(x, y): return (x in a and y in b) or (x in b and y in a) return all(sym(x, y) for x,y in combs) print(main())