File talk:Constellations, equirectangular plot.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

New four-colouring[edit]

New four-colouring

@Pruthviraya: suggested to me the possibility of four-colouring the chart while having 22 constellations of each colour. However, I found that his or her suggestion causes two adjacent regions to have the same colour.

As @Timwi: helped me four-colour the chart ten years ago, I approached him again with the constraint, in addition to keeping both parts of Serpens the same colour, and each of the four quadripoints having 4 different colours. In under an hour, he came up with this colouring:

(AND, 3); (ANT, 3); (APS, 2); (AQL, 1); (AQR, 0); (ARA, 3); (ARI, 2); (AUR, 2); (BOO, 1); (CAE, 0); (CAM, 3); (CAP, 2); (CAR, 0); (CAS, 0); (CEN, 2); (CEP, 2); (CET, 3); (CHA, 1); (CIR, 1); (CMA, 1); (CMI, 0); (CNC, 2); (COL, 2); (COM, 0); (CRA, 0); (CRB, 2); (CRT, 0); (CRU, 1); (CRV, 3); (CVN, 3); (CYG, 3); (DEL, 3); (DOR, 2); (DRA, 0); (EQU, 1); (ERI, 2); (FOR, 1); (GEM, 3); (GRU, 1); (HER, 3); (HOR, 3); (HYA, 1); (HYI, 1); (IND, 2); (LAC, 1); (LEO, 3); (LEP, 3); (LIB, 3); (LMI, 1); (LUP, 0); (LYN, 0); (LYR, 1); (MEN, 0); (MIC, 0); (MON, 2); (MUS, 3); (NOR, 2); (OCT, 3); (OPH, 2); (ORI, 1); (PAV, 0); (PEG, 2); (PER, 1); (PHE, 3); (PIC, 1); (PSA, 3); (PSC, 1); (PUP, 3); (PYX, 0); (RET, 0); (SCL, 2); (SCO, 1); (SCT, 2); (SER, 0); (SEX, 2); (SGE, 2); (SGR, 3); (TAU, 0); (TEL, 1); (TRA, 0); (TRI, 0); (TUC, 0); (UMA, 2); (UMI, 1); (VEL, 1); (VIR, 2); (VOL, 3); (VUL, 0)

using the C♯ program below with these dependencies:

var adjs = File.ReadLines(@"D:\temp\edges_18.txt")
    .Select(line => Regex.Match(line, @" (...)[12]? (...)[12]?$"))
    .Where(m => m.Success)
    .Select(m => new[] { m.Groups[1].Value, m.Groups[2].Value }.Order().ToArray())
    .Select(ar => (ar[0], ar[1]))
    .Distinct()
    .ToArray();
var constellations = adjs.SelectMany(tup => new[] { tup.Item1, tup.Item2 }).Distinct().ToArray();

var puzzle = new Puzzle(constellations.Length, 0, 3);
puzzle.AddConstraint(new LambdaConstraint(affectedCells: Enumerable.Range(0, constellations.Length), lambda: state =>
{
    var counts = new int[4];
    for (var cell = 0; cell < state.GridSize; cell++)
        if (state[cell] is int color)
            counts[color]++;
    for (var color = 0; color < 4; color++)
        if (counts[color] == 22)
            for (var cell = 0; cell < state.GridSize; cell++)
                state.MarkImpossible(cell, color);
    return null;
}));
foreach (var (c1, c2) in adjs)
    puzzle.AddConstraint(new TwoCellLambdaConstraint(constellations.IndexOf(c1), constellations.IndexOf(c2), (v1, v2) => v1 != v2));

var quadri = Ut.NewArray(
    @"SGR TEL IND MIC",
    @"HYA CEN LUP LIB",
    @"LYN CNC LEO LMI",
    @"PHE TUC HYI ERI")
    .Select(str => str.Split(' '))
    .SelectMany(ar => ar.UniquePairs().Select(pair => new TwoCellLambdaConstraint(constellations.IndexOf(pair.Item1), constellations.IndexOf(pair.Item2), (v1, v2) => v1 != v2)));
puzzle.AddConstraints(quadri);

var solution = puzzle.Solve(new SolverInstructions { Randomizer = new Random(47) }).First();
Console.WriteLine(Enumerable.Range(0, constellations.Length).Select(ix => (name: constellations[ix], color: solution[ix])).OrderBy(p => p.name).JoinString("; "));
Console.WriteLine(Enumerable.Range(0, 4).Select(c => solution.Count(s => s == c)).JoinString(", "));

After updating the Perl script, I regenerated the SVG above with this online Perl interpreter which allows file input and output. cmɢʟee ⋅τaʟκ 19:12, 23 June 2023 (UTC)[reply]