// Exact finite checks of the labelled graph model. Run with Node.js. function subsets(items, count, start, chosen, visit) { if (chosen.length === count) return visit(chosen); for (let i = start; i <= items.length - count + chosen.length; i++) { chosen.push(items[i]); subsets(items, count, i + 1, chosen, visit); chosen.pop(); } } function countTours(graph) { const used = new Set([0]); function extend(v) { if (used.size === graph.length) return Number(graph[v].includes(0)); let ways = 0; for (const w of graph[v]) { if (used.has(w)) continue; used.add(w); ways += extend(w); used.delete(w); } return ways; } return extend(0) / 2; } function check(m) { const h = 2*m; const edges = []; for (let a=0; a { const graph = Array.from({length: 3*m}, () => []); function add(a,b) { graph[a].push(b); graph[b].push(a); } for (const [a,b] of factor) add(a,b); if (graph.slice(0,h).some(row => row.length !== 2)) return; for (let i=0; i { const partner = new Map(); for (const [a,b] of matching) { partner.set(a,b); partner.set(b,a); } if (partner.size !== h) return; let v=0, reached=0; do { v=partner.get(v)^1; reached+=2; } while (v!==0); if (reached===h) viaMatchings++; }); if (direct !== viaMatchings) throw Error("Cycle counts disagree"); histogram.set(direct, (histogram.get(direct)||0)+1); }); return [...histogram].sort((a,b)=>a[0]-b[0]); } for (const m of [2,3]) console.log(m,JSON.stringify(check(m)));