#!/usr/bin/env python3 from z3 import * COUPLES=3 # a pair each men and women related to: men=[Int('men_%d' % i) for i in range(COUPLES)] women=[Int('women_%d' % i) for i in range(COUPLES)] # men and women are placed around table like this: # m m m # w w w # i.e., women[0] is placed between men[0] and men[1] # the last women[COUPLES-1] is between men[COUPLES-1] and men[0] (wrapping) s=Solver() s.add(Distinct(men)) s.add(Distinct(women)) [s.add(And(men[i]>=0, men[i]=0, women[i]