Perl Monk, Perl Meditation PerlMonks

### comment on

 Need Help??
Update: A while ago I saw an absolutely fantastic piece of art on film. It was only a minute or two long. The artist had done some visual thing, but the highlight for me was that he/she had a person reading words that were joined together, similar to what I did to MeowChows post below. It was always just on the edge of understandable. I think it was called 'Mouth Music'. Anyway, it rocked.

Well, here's code that does some of what you want. What I would really like to see is a mathematical proof of the minimum number and length of sequences to get complete reconstruction of the thing you chopped up in the first place.

Plus, when you golf, aren't you meant to post your own code for other people to play with? Maybe I should call homework on this :)

Here are the results:

```logger,gerbil,log,analog,
Constructed sequence is analoggerbil

GATTACA,ATTACA,GATT,AAGAT,CCC,
Constructed sequence is gattacaagatt

Fragment,Reassembly,by,MeowChow,...
Constructed sequence is byoureassemblesuperstringolfednakasubstringseq
+uencing
[download]```

And here is the code that did it:

```use strict;
sub assemble{
my @sequences = sort {length(\$b) <=> length(\$a)} @_;
&text_mangle(\$_) for @sequences;
my \$a=shift @sequences;
my \$b=shift @sequences;
while ( @sequences ) {
my \$c=overlap(\$a,\$b);
if ( defined(\$c) ) {
\$a=\$c;
#push @sequences,\$b;
\$b=shift @sequences;
}
else
{
push @sequences,\$b;
\$b=shift @sequences;
}
}
print "Constructed sequence is \$a\n";
};
sub overlap{
my (\$a,\$b)=@_;
my (\$i,\$l);
if (\$a=~/ / || \$b=~/ / ) { die "Don't use spaces in your data!
+\n";}
\$l=length(\$a);
for (\$i=0;\$i<\$l; \$i++ ) {
if ( substr(\$a,\$i,\$l-\$i) eq substr(\$b,0,\$l-\$i) ) {
substr(\$a,\$i,(\$l-\$i))=  \$b;
return \$a;
}
}

\$l=length(\$b);
for (\$i=0;\$i<\$l; \$i++ ) {
if ( lc(substr(\$b,\$i,\$l-\$i)) eq lc(substr(\$a,0,\$l-\$i))
+ ) {
substr(\$b,\$i,(\$l-\$i))= \$a ;
return \$b;
}
return undef;
};
sub text_mangle {
\$_[0]=~s/ |\.|\,//g;
my \$a=lc(\$_[0]);
\$_[0]=\$a;

}
sub swap {
my \$a=\$_[0];
\$_[0]=\$_[1];
\$_[1]=\$a;
}

my @array=qw(logger gerbil log analog);
foreach (@array) {print; print ",";};print "\n";assemble(@array);print
+ "\n";
@array=qw(GATTACA ATTACA GATT AAGAT CCC);
foreach (@array) {print; print ",";};print "\n";assemble(@array);print
+ "\n";
@array=qw(Fragment Reassembly by MeowChow
... aka DNA Sequencing or Shortest Common Superstring. Your mission, s
+hould you choose to accept it, is to design a golfed sforeach (@array
+) {print; print ",";};print "\n";assemble(@array);print "\n";
[download]```

____________________
Jeremy
I didn't believe in evil until I dated it.

In reply to Re: (Golf) Fragment Reassembly by jepri
in thread (Golf) Fragment Reassembly by MeowChow

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 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? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2022-01-18 15:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In 2022, my preferred method to securely store passwords is:

Results (53 votes). Check out past polls.

Notices?