"""A graph in which every vertex has three neighbours, with a cycle of length a power of two: the Petersen graph has no cycle of length 4 (its shortest cycles have length 5), so 8 is the first power of two it could have, and it does.""" import itertools import math from pathlib import Path import kit # outer 5-cycle 0..4, spokes i - i+5, inner pentagram 5+i - 5+(i+2)%5 E = {frozenset(e) for i in range(5) for e in ((i, (i + 1) % 5), (i, i + 5), (5 + i, 5 + (i + 2) % 5))} adj = {v: {w for e in E if v in e for w in e if w != v} for v in range(10)} assert all(len(adj[v]) == 3 for v in adj) def has_cycle(k): return any(all(frozenset((c[i], c[(i + 1) % k])) in E for i in range(k)) for c in itertools.permutations(range(10), k) if c[0] == min(c)) assert not has_cycle(4) and not has_cycle(3) C = [0, 1, 2, 3, 4, 9, 7, 5] on = {frozenset((C[i], C[(i + 1) % 8])) for i in range(8)} assert len(set(C)) == 8 and on <= E cx, cy = kit.W / 2, 132 def at(v): a, rr = -math.pi / 2 + 2 * math.pi * (v % 5) / 5, (118 if v < 5 else 54) return cx + rr * math.cos(a), cy + rr * math.sin(a) body = [kit.line(*at(a), *at(b), 'faint-s', 2) for a, b in map(tuple, E - on)] body += [kit.line(*at(a), *at(b), 'f-s', 5) for a, b in map(tuple, on)] body += [kit.dot(*at(v), 8) for v in range(10)] kit.write(__file__, 'mathematics', ''.join(body), label='3 neighbours each ยท no cycle of 4, but one of 8')