summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-11-18 18:10:08 -0600
committerJesse Luehrs <doy@tozt.net>2012-11-18 18:10:08 -0600
commitccbec87cef4c99c8f62a3ee7aad3e20f93c4efe6 (patch)
tree0a251ba58b59748dcf0b961aecc3205b1bcc83fd
parent02c329a876fdfec61cd65f8f67fd0e7c9252787d (diff)
downloadrosalind-ccbec87cef4c99c8f62a3ee7aad3e20f93c4efe6.tar.gz
rosalind-ccbec87cef4c99c8f62a3ee7aad3e20f93c4efe6.zip
another solution
-rw-r--r--LONG.pl37
1 files changed, 37 insertions, 0 deletions
diff --git a/LONG.pl b/LONG.pl
new file mode 100644
index 0000000..6046050
--- /dev/null
+++ b/LONG.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.016;
+
+chomp(my @lines = <>);
+
+my $full = shift @lines;
+while (@lines) {
+ my $found;
+ my $found_length = 0;
+ my $before;
+ for my $i (0..$#lines) {
+ for my $len (reverse 1..length($lines[0])) {
+ last if $len <= $found_length;
+ if (substr($full, 0, $len) eq substr($lines[$i], -$len)) {
+ $found_length = $len;
+ $found = $i;
+ $before = 1;
+ }
+ elsif (substr($full, -$len) eq substr($lines[$i], 0, $len)) {
+ $found_length = $len;
+ $found = $i;
+ $before = 0;
+ }
+ }
+ }
+ my $str = splice(@lines, $found, 1);
+ if ($before) {
+ $full = substr($str, 0, -$found_length) . $full;
+ }
+ else {
+ $full = $full . substr($str, $found_length);
+ }
+}
+
+say $full;