Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[shootout/regex-dna] add version that works on Rakudo
the .subst() call is what causes the excessive memory consumption
of the original version
  • Loading branch information
gerdr committed May 14, 2012
1 parent 7a64336 commit 220cec7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions shootout/regex-dna.p6-v2.pl
@@ -0,0 +1,26 @@
use v6;

my $input = slurp;
my $data = $input.lines.grep({ $_ !~~ /^ \>/}).join.lc;

say $_ ~ ' ' ~ +$data.comb($_) for
/agggtaaa|tttaccct/ but 'agggtaaa|tttaccct',
/<[cgt]>gggtaaa|tttaccc<[acg]>/ but '[cgt]gggtaaa|tttaccc[acg]',
/a<[act]>ggtaaa|tttacc<[agt]>t/ but 'a[act]ggtaaa|tttacc[agt]t',
/ag<[act]>gtaaa|tttac<[agt]>ct/ but 'ag[act]gtaaa|tttac[agt]ct',
/agg<[act]>taaa|ttta<[agt]>cct/ but 'agg[act]taaa|ttta[agt]cct',
/aggg<[acg]>aaa|ttt<[cgt]>ccct/ but 'aggg[acg]aaa|ttt[cgt]ccct',
/agggt<[cgt]>aa|tt<[acg]>accct/ but 'agggt[cgt]aa|tt[acg]accct',
/agggta<[cgt]>a|t<[acg]>taccct/ but 'agggta[cgt]a|t[acg]taccct',
/agggtaa<[cgt]>|<[acg]>ttaccct/ but 'agggtaa[cgt]|[acg]ttaccct';

say;

my %iub = 'b' => '(c|g|t)', 'd' => '(a|g|t)', 'h' => '(a|c|t)',
'k' => '(g|t)', 'm' => '(a|c)', 'n' => '(a|c|g|t)',
'r' => '(a|g)', 's' => '(c|g)', 'v' => '(a|c|g)',
'w' => '(a|t)', 'y' => '(c|t)';

my $output = $data.comb.map({ %iub{$^c} // $^c }).join;

.chars.say for $input, $data, $output;

0 comments on commit 220cec7

Please sign in to comment.