Hi all,
Forgive me for reposting. I pressed 'create' mistakenly. Also there is some segment missed out in the code before. This is the first time I post here.
I have a following code that find a "k-clique" within a graph.
k-Clique is a complete subgraph of size 'k'.
Currently running this code gives:
$ perl graph.pl 3 5 6 9 $ perl graph.pl 4 1 2 3 4
As you can see the code below only return the "last" k-clique found. My question is how can I modify my code below so it can store and then returns all the "k-clique" found? That is:
$ perl graph.pl 3 would give: 1 2 3 1 2 4 1 3 4 2 3 4 5 6 9
Charles suggested that I use loop to step through the vertices or regex for the second part of the string.
But I still can't figure it out in concrete way.
Seems that my regex knowledge is too limited.
Dear monks, to you now I turn too...
Thanks beforehand!

Regards,
Edward WIJAYA
_BEGIN__ #Credit Greg Bacon #and suggestion by C.Clarkson my @vertices = 1 .. 9; my @edges = ( [1,2], [1,3], [1,4], [1,5], [2,3], [2,4], [3,4], [5,6], [5,7], [5,9], [6,9], [7,8], [8,9], ); $k = shift || 3; #Construct a string as follows: $string = (join ',' => @V) . ';' . (join ',' => map "$_->[0]-$_->[1]", @E); #Then construct a regular expression as follows: $regex = '^ .*\b ' . join(' , .*\b ' => ('(\d+)') x $k) . '\b .* ;' . "\n"; for ($i = 1; $i < $k; $i++) { for ($j = $i+1; $j <= $k; $j++) { $regex .= '(?= .* \b ' . "\\$i-\\$j" . ' \b)' . "\n"; } } #Our graph contains a k-clique if and only if if ($string =~ /$regex/x) { print join(" ", map $$_, 1..$k), "\n"; } __END__

In reply to Finding number of 'k'-clique in a graph by monkfan

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.