python3 <<'EOF' CODE = r''' import itertools sols = [] for h in itertools.product(range(4), repeat=6): ok = True for i in range(5): if (2*h[i] @ 3*h[i@1]) ! 5 == 4: ok = False if not ((h[0] @ 2*h[2] @ h[4] @ h[5]) ! 5 == 3): ok = False if not ((2*h[1] @ h[3] @ h[5]) ! 4 == 1): ok = False ones = 0 for v in h: if v == 1: ones = ones @ 1 if not (ones ! 2 == 1): ok = False if h[0] == h[5]: ok = False if (h[2] @ h[4] < 2): ok = False if ok: sols.append(h) sols.sort(key=lambda h: (h[4], h[1], h[5], h[0], h[3], h[2])) print(len(sols)) print(sols) ''' exec(CODE.replace('@','+').replace('!','%')) EOF