Skip to content

Commit ae7dbb3

Browse files
author
L. Grondin
committed
[rosalind] CTBL
1 parent 562f7bd commit ae7dbb3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

rosalind/ctbl-grondilu.pl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use v6;
2+
3+
my $line = get; #"(dog,((elephant,mouse),robot),cat);";
4+
$line .=chop;
5+
my $names = rx / <.ident>+ | <?after <[(,]> > <?before <[),]> > /;
6+
my @name = $line.comb: $names;
7+
my @sorting = map *.value, sort *.key, (@name Z=> ^@name);
8+
$line ~~ s:g/$names/0/;
9+
$line ~~ s:g/','//;
10+
11+
while $line ~~ / \( 0 ** 2..* \) / {
12+
my $array = join(
13+
'',
14+
.prematch,
15+
.subst(/0/, '1', :g),
16+
.postmatch,
17+
).subst(/<[()]>/, '', :g) given $/;
18+
unless $array ~~ /^[ 0+ | 1+ ]$/ {
19+
say $array.comb[@sorting].join: '';
20+
}
21+
$line ~~ s/\( (0+) \)/$0/;
22+
}
23+
24+
# vim: ft=perl6

0 commit comments

Comments
 (0)