Answer the question
In order to leave comments, you need to log in
Simple genomic compiler (sequence analysis)?
There are sequences of characters, you need to assemble the original sequence, only if there is only one option, you can connect sequences only if they intersect with at least one character, for example, abbb and vccp can be combined into abbvcp, vavv + vvab \u003d vaab, tell me how to implement?
Answer the question
In order to leave comments, you need to log in
The task is not complete, because what "desired" sequence will depend on the order in which the fragments will be taken and there is no guarantee that in the end there will be no "incompatible fragments".
If, in the context of the task, there is a kind of "puzzle" that has only 1 solution, then you will have to make a complete enumeration of all possible solutions, which will require approximately N * (N ^ N) operations, that is, for only 10 fragments it will be approximately equal to "pzc how many zeros the calculator is broken", and if there are 200 of them ....
The output of the problem is not complete, for adequacy there are not enough any limiters.
Modified v2
<code lang="cs">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<string> coll = new List<string>();
for (int i = 0; i < args.Length; i++)
{ coll.Add(args[i]); }
Genome GG = new Genome();
string s = GG.GetConcatGenom(coll);
Console.WriteLine(s);
Console.ReadKey();
//GetConcatGenom(coll);
}
}
public class Genome
{
public string GetConcatGenom(List<String> genoms)
{
List<string> sss = new List<string>();
foreach (var item in genoms)
{
List<string> newgen = new List<string>(genoms);
newgen.Remove(item);
string curres = ConcatRecursive(item, newgen);
sss.Add(curres);
//Console.WriteLine(curres);
}
return "OK";
}
public string ConcatRecursive(string s, List<String> genoms)
{
if (genoms.Count == 0)
{
return s;
}
for (int j = 0; j < genoms.Count; j++)
{
List<String> gens = new List<String>(genoms);
string newgen = s;
//if (genoms.Count == 0) { return newgen ; }
int minlen = Math.Min(genoms[j].Length, newgen.Length);
bool finded = false;
for (int i = minlen; i > 0; i--)
{
if (finded )
{
break;
}
if (newgen.EndsWith(genoms[j].Substring(0, i)))
{
finded = true;
newgen = newgen.Substring(0, newgen.Length - i);
newgen += genoms[j];
gens.Remove(genoms[j]);
if (gens.Count == 0)
{
return newgen;
}
else
{
string curres = ConcatRecursive(newgen, gens);
if (curres != "")
{
Console.WriteLine(curres);
}
}
}
}
}
return "";
}
}
}
</code>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question