Cycles of length a power of two (the Erdős–Gyárfás conjecture)
Show that every finite graph with minimum degree 3 has a cycle of length 4, 8, 16 or another power of two, or find a counterexample.

| 1 | """A graph in which every vertex has three neighbours, with a cycle of length a power of two: the Petersen graph has |
| 2 | 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.""" |
| 3 | import itertools |
| 4 | import math |
| 5 | from pathlib import Path |
| 6 | |
| 7 | import kit |
| 8 | |
| 9 | # outer 5-cycle 0..4, spokes i - i+5, inner pentagram 5+i - 5+(i+2)%5 |
| 10 | E = {frozenset(e) for i in range(5) for e in ((i, (i + 1) % 5), (i, i + 5), (5 + i, 5 + (i + 2) % 5))} |
| 11 | adj = {v: {w for e in E if v in e for w in e if w != v} for v in range(10)} |
| 12 | assert all(len(adj[v]) == 3 for v in adj) |
| 13 | |
| 14 | |
| 15 | def has_cycle(k): |
| 16 | return any(all(frozenset((c[i], c[(i + 1) % k])) in E for i in range(k)) |
| 17 | for c in itertools.permutations(range(10), k) if c[0] == min(c)) |
| 18 | |
| 19 | |
| 20 | assert not has_cycle(4) and not has_cycle(3) |
| 21 | C = [0, 1, 2, 3, 4, 9, 7, 5] |
| 22 | on = {frozenset((C[i], C[(i + 1) % 8])) for i in range(8)} |
| 23 | assert len(set(C)) == 8 and on <= E |
| 24 | |
| 25 | cx, cy = kit.W / 2, 132 |
| 26 | |
| 27 | |
| 28 | def at(v): |
| 29 | a, rr = -math.pi / 2 + 2 * math.pi * (v % 5) / 5, (118 if v < 5 else 54) |
| 30 | return cx + rr * math.cos(a), cy + rr * math.sin(a) |
| 31 | |
| 32 | |
| 33 | body = [kit.line(*at(a), *at(b), 'faint-s', 2) for a, b in map(tuple, E - on)] |
| 34 | body += [kit.line(*at(a), *at(b), 'f-s', 5) for a, b in map(tuple, on)] |
| 35 | body += [kit.dot(*at(v), 8) for v in range(10)] |
| 36 | kit.write(__file__, 'mathematics', ''.join(body), label='3 neighbours each · no cycle of 4, but one of 8') |