You’re right, thanks! I forgot to include the OP’s code for sorting the path arrays according to number of elements. Node updated:
...
@paths = sort { @$a <=> @$b } @paths;
my @sets;
push @sets, set(@$_) for @paths;
my @filtered;
...
Now the output for your input data is as follows:
16:12 >perl 1681_SoPW.pl
(Q R V)
(C D V)
(N P Q)
(E T V X)
(E N O P)
(I N T U Z)
(B D R W Z)
(A N O X Z)
(B L O R T)
(D H S X Y)
(D F J K O P T)
(D J M R S T V)
(B H J L N P U)
(A B H P R V X)
(C F L M T Y)
(C I J L M O X Y)
(D H I P S T V Y)
(A B D F G O U W)
(A C D E H J L N S Z)
(D F G M O S U W Y)
(A C G H J K P V Z)
(E H K M N P T V)
(F H I L O T V Z)
16:12 >
Update: Since sets contain no duplicate elements, it will be better to sort on number of elements after the arrays have been converted into sets:
...
my @sets;
push @sets, set(@$_) for @paths;
@sets = sort { $a->size <=> $b->size } @sets;
my @filtered;
...
Output:
17:06 >perl 1681_SoPW.pl
(Q R V)
(C D V)
(N P Q)
(E N O P)
(E T V X)
(D H S X Y)
(I N T U Z)
(B D R W Z)
(A N O X Z)
(B L O R T)
(C F L M T Y)
(B H J L N P U)
(A B H P R V X)
(D F J K O P T)
(D J M R S T V)
(E H K M N P T V)
(F H I L O T V Z)
(D H I P S T V Y)
(A B D F G O U W)
(C I J L M O X Y)
(D F G M O S U W Y)
(A C G H J K P V Z)
(A C D E H J L N S Z)
17:08 >
Cheers,
-
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.
|