Add sage code

This commit is contained in:
2026-04-15 20:23:44 -04:00
parent c2298339ce
commit fc277760af
10 changed files with 273 additions and 1 deletions
+19
View File
@@ -0,0 +1,19 @@
"""Utilities for converting integer colorings to named colors."""
from typing import Any
COLORS = ['blue', 'red', 'green', 'yellow', 'purple']
def convert_coloring(
coloring: dict[Any, int],
vertices: list[Any] | None = None
) -> dict[str, list[Any]]:
"""Convert an integer coloring dict to a dict mapping color names to vertex lists."""
colors: dict[str, list[Any]] = {}
for k, v in coloring.items():
if vertices and k not in vertices:
continue
color = COLORS[v]
if color not in colors:
colors[color] = []
colors[color].append(k)
return colors