Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

If solution is thought of as symmetric matrix with all-unique elements (i.e. "edge labels") per row (and therefore, per column) and crossed-out dummy diagonal, then quite formal algorithm to build it could be as follows. Code is not pretty, at least I hope I streamlined it enough after couple of, even uglier, attempts.

use strict; use warnings; use feature 'say'; use constant LETTERS => join '', 'A'..'Z', 'a'..'z'; # template use constant N => 51; # number of "e +dges" die if not N % 2 # (1) prohibit odd nodes number or N > 51; # (2) "template" limitation say '_' . substr LETTERS, 0, N; my $last = substr LETTERS, N - 1, 1; # "collect" last line here for ( 1 .. N - 1 ) { my $s = substr LETTERS, 0, N; my $sfx = substr $s, 0, $_ - 1, ''; $s .= $sfx; # rotate left $sfx = substr $s, $_, 1, '_'; $s .= $sfx; # ...& append replaced diagona +l item say $s; $last .= substr $s, -1; } say $last . '_'; __END__

Extended 2:53 2/20/22: now here's formal generation code for both odd/even number of "edges", at expense of introducing additional "edge label" (a star) in latter case:

use strict; use warnings; use feature 'say'; use constant LETTERS => join '', 'A'..'Z', 'a'..'z'; use constant N => 12; say '_' . substr LETTERS, 0, N; my $last = substr LETTERS, N - 1, 1; for ( 1 .. N - 1 ) { my $s = substr LETTERS, 0, N; my $sfx = substr $s, 0, $_ - 1, ''; $s .= '*' unless N % 2; $s .= $sfx; $sfx = substr $s, $_, 1, '_'; $s .= $sfx if N % 2; say $s; $last .= substr $s, -1; } say $last . '_'; __END__ _ABCDEFGHIJKL A_CDEFGHIJKL* BC_EFGHIJKL*A CDE_GHIJKL*AB DEFG_IJKL*ABC EFGHI_KL*ABCD FGHIJK_*ABCDE GHIJKL*_BCDEF HIJKL*AB_DEFG IJKL*ABCD_FGH JKL*ABCDEF_HI KL*ABCDEFGH_J L*ABCDEFGHIJ_

In reply to Re: Graph labeling problem by vr
in thread Graph labeling problem by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found