Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/replies, xml ) 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

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";

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

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (5)
    As of 2017-12-12 11:07 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (330 votes). Check out past polls.