in reply to Graph labeling problem

Here's solutions for 2,4,6,8,10 and proves? none for 3,5,7

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11141490 use warnings; use ntheory qw( forperm ); use List::AllUtils qw( none ); for my $n ( 2 .. 8, 10 ) { my @cols; forperm { my $c = join '', map +('-', 'a'..'z', 'A' .. 'Z')[$_], @_; push @{ $cols[ index $c, '-' ] }, $c } $n; my $start = $cols[0][0]; eval { find( "$start\n", @cols[1 .. $#cols ] ) }; } sub transpose { (local $_, my $new) = (shift, ''); $new .= "\n" while s/^./ $new .= $&; ''/gem; return $new; } sub find { my ($have, @next) = @_; my $flip = transpose($have); @next or $have eq $flip and warn( "$have\n"), die; my $pat = (split /\n/, $flip)[index $flip, "\n"]; my @haves = split /\n/, $have; my $trys = shift @next; for my $try ( grep /^$pat/, @$trys ) { none { ("$try" ^ "$_") =~ tr/\0// } @haves, and find( "$have$try\n", @next ); } }

Outputs:

-a a- -abc a-cb bc-a cba- -abcde a-cdeb bc-ead cde-ba deab-c ebdac- -abcdefg a-cbedgf bc-afgde cba-gfed defg-abc edgfa-cb fgdebc-a gfedcba- -abcdefghi a-cbedgfih bc-afghide cba-ghidef defg-iahbc edghi-bcfa fghiab-ecd gfidhce-ab hidebfca-g ihefcadbg- real 0m8.080s user 0m7.986s sys 0m0.090s

I think you are dealing with factorials, so good luck with 50 factorial!!

On the other hand, I could be wrong...

Replies are listed 'Best First'.
Re^2: Graph labeling problem (odd n => n colors)
by LanX (Saint) on Feb 20, 2022 at 12:28 UTC
    > proves? none for 3,5,7

    That prove is easy for n odd.

    All k edges of same color of a hypothetical solution connect at most 2k different nodes.

    But n is odd, hence one node must skip that color.

    Or

    A complete graph Kn has n*(n-1)/2 edges and (n-1)/2 is the max number of edges of same color for n odd.

    So n is the min of needed colors.

    And I've already shown an easy construction with n colors for all Kn (odd and even).

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Re^2: Graph labeling problem (even n => n-1 colors)
by LanX (Saint) on Feb 20, 2022 at 13:04 UTC
    > I think you are dealing with factorials, so good luck with 50 factorial!!

    the wikipedia article shows an easy construction for an even n with n-1 colors.

    A picture showing the solution for K8 is given too.

    Basically, if you have a regular n-1 polygon plus it's center and connect all the nodes you'll have a Kn graph. Because of the regularity this graph has n-1 groups of (n-2)/2 parallel edges plus one perpendicular from the center m to the missing node. Parallel edges can never be adjacent.

    I tried to sketch it for K6 with a pentagram a b c d e and a center m

    d | e---------c m a-----b

    Of course it's hard to draw a regular pentagram in ASCI graphic, the display will also depend on your browser settings.

    But I hope it's obvious that symmetry leads to a solution with 5 colors here, which can be generalized to n even.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery