Edward WIJAYA <[EMAIL PROTECTED]> wrote: : My question is how can I modify my code below : so it can store and then returns all the "k-clique" found?
That's a tough one. The regex was designed to see if there was at least one k-clique in a graph -- not to find all of them. You'll need to get better control over the vertices. That's the first line of the regex. / .*\b (\d+) , .*\b (\d+) , .*\b (\d+)\b .* ; (?= .* \b \1-\2 \b) (?= .* \b \1-\3 \b) (?= .* \b \2-\3 \b) /x I don't know enough about regexes to step through each solution. I would probably resort to the use of a loop to step through the vertices and perhaps a regex for the second part of the string. 1-2,1-3,1-4,2-3,2-4,3-4,1-5,5-6,5-9,5-7,7-8,8-9,6-9 HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 Here's a version of the current script that uses strict. I would suggest you play with it rather than the one you presented. #!/usr/bin/perl use strict; use warnings; 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], ); # Build regular expression my $k = shift || 3; my $regex = '.*\b ' . join(' , .*\b ', ('(\d+)') x $k) . '\b .* ;' . "\n"; foreach my $i ( 1 .. $k - 1 ) { foreach my $j ( $i + 1 .. $k ) { $regex .= '(?= .* \b ' . "\\$i-\\$j" . ' \b)' . "\n"; } } # Build string my $string = join( ',', @vertices) . ';' . join( ',', map "$_->[0]-$_->[1]", @edges); # Test for at least one k-clique if ( $string =~ /$regex/x ) { print "($1, $2, $3)\n"; } __END__ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>