查找基因中的不相交基序
作者:grondilu
http://rosalind.info/problems/itwv/
示例输入
GACCACGGTT ACAG GT CCG
示例输出
0 0 1 0 1 0 1 0 0
源代码: itwv-grondilu.pl
use v6; # THIS IS WAY TOO SLOW!! # my $dna = 'GACCACGGTT'; my @motif = <ACAG GT CCG>; sub interwove($a, $b) { gather if none($a, $b) eq '' { for &?ROUTINE($a.substr(1), $b) { take $a.substr(0,1) ~ $_ } for &?ROUTINE($a, $b.substr(1)) { take $b.substr(0,1) ~ $_ } } elsif $a eq '' { take $b } else { take $a } } my %seen; for @motif -> $a { my @arr = gather for @motif -> $b { my @interwove = interwove($a, $b).unique; take %seen{sort($a, $b).join(':')} //= +so grep rx/ <@interwove> /, $dna; } say "{@arr}" }