Created
April 9, 2022 18:46
-
-
Save jcreedcmu/9b2ca8b3afb962dc00c70fe7a641693e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prodf(xs, ys, f) { | |
const rv = []; | |
for (let i = 0; i < xs.length; i++) { | |
for (let j = 0; j < ys.length; j++) { | |
rv.push(f(xs[i], ys[j])); | |
} | |
} | |
return rv; | |
} | |
function list(n) { | |
if (n == 0) { | |
return []; | |
} | |
if (n == 1) { | |
return ['x']; | |
} | |
else { | |
let rv = []; | |
for (let i = 1; i <= n - 1; i++) { | |
rv = rv.concat(prodf(list(i), list(n-i), (a, b) => [a,b])); | |
} | |
return rv; | |
} | |
} | |
function colorings(tree, c) { | |
if (tree == 'x') return [c + '']; | |
else { | |
const opts1 = prodf(colorings(tree[0], (c + 1) % 3), colorings(tree[1], (c + 2) % 3), (a, b) => a + b); | |
const opts2 = prodf(colorings(tree[0], (c + 2) % 3), colorings(tree[1], (c + 1) % 3), (a, b) => a + b); | |
return opts1.concat(opts2); | |
} | |
} | |
// x is a string over 0, 1, 2 | |
function canonical(x) { | |
function rewrite(x, p) { | |
return x.replace(/./g, c => p[parseInt(c)]); | |
} | |
return ['012', '021', '201', '210', '120', '102'].map(p => rewrite(x, p)).sort()[0]; | |
} | |
function cstring(t) { | |
return [...new Set(colorings(t, 0).map(canonical))].sort().join('-'); | |
} | |
function intersect(s1, s2) { | |
let count = 0; | |
for (const c of s1) { | |
if (s2.has(c)) count++; | |
} | |
return count; | |
} | |
const i = 8; | |
const css = list(i).map(cstring).map(s => new Set(s.split('-'))); | |
for (let j = 0; j < css.length; j++) { | |
let s = ''; | |
for (let k = 0; k < css.length; k++) { | |
s += ' ' + intersect(css[j], css[k]); | |
} | |
console.log(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment