aboutsummaryrefslogtreecommitdiff
path: root/challenge-145
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-01-02 22:19:37 +0000
committerdrbaggy <js5@sanger.ac.uk>2022-01-02 22:19:37 +0000
commitba08d9700618c5b65cac87f70517c40dd7af5429 (patch)
tree64a7379a6daa63c745d4d8b1f54cf9483f105ef7 /challenge-145
parent152fc563c642a6e32dcef13753cc3762dea710f1 (diff)
downloadperlweeklychallenge-club-ba08d9700618c5b65cac87f70517c40dd7af5429.tar.gz
perlweeklychallenge-club-ba08d9700618c5b65cac87f70517c40dd7af5429.tar.bz2
perlweeklychallenge-club-ba08d9700618c5b65cac87f70517c40dd7af5429.zip
separate out stringify
Diffstat (limited to 'challenge-145')
-rw-r--r--challenge-145/james-smith/perl/ch-2.pl19
1 files changed, 11 insertions, 8 deletions
diff --git a/challenge-145/james-smith/perl/ch-2.pl b/challenge-145/james-smith/perl/ch-2.pl
index 9748778fbf..6e10b86065 100644
--- a/challenge-145/james-smith/perl/ch-2.pl
+++ b/challenge-145/james-smith/perl/ch-2.pl
@@ -21,7 +21,7 @@ my @TESTS = (
[ 'llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch', 'l ll a n f i r p w g y gog o e c h d b lll llll t s ili ogo ogogo ogogogo gogog' ],
);
-is( eertree($_->[0]), $_->[1] ) for @TESTS;
+is( stringify( eertree($_->[0]) ), $_->[1] ) for @TESTS;
done_testing();
sub eertree {
@@ -37,13 +37,7 @@ sub eertree {
add_str( $tree, $str, -1, $_, $_ ),
add_str( $tree, $str, q(), $_, $_+1 ) for 0.. @{$str}-1;
- ## grab nodes and sort into start/length order and join....
- return join q( ),
- sort { $tree->{$a}{'start'} <=> $tree->{$b}{'start'} ||
- length $a <=> length $b
- }
- grep { defined $tree->{$_}{'start'} }
- keys %{$tree};
+ $tree;
}
sub add_str {
@@ -69,3 +63,12 @@ sub add_str {
}
}
+sub stringify {
+ my $tr = shift;
+ join q( ),
+ sort { $tr->{$a}{'start'} <=> $tr->{$b}{'start'} ||
+ length $a <=> length $b
+ }
+ grep { defined $tr->{$_}{'start'} }
+ keys %{$tr};
+}