aboutsummaryrefslogtreecommitdiff
path: root/challenge-057
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-04-24 22:25:45 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-04-24 22:25:45 +0100
commitbc5dc73644cad234b113d44ed80a466faf996401 (patch)
tree5e9ac0ed9be7c9b323606dbfe7b1ec50cead5f04 /challenge-057
parentb543bf6fe7645c0779a9de273ae4ab3477c545d7 (diff)
downloadperlweeklychallenge-club-bc5dc73644cad234b113d44ed80a466faf996401.tar.gz
perlweeklychallenge-club-bc5dc73644cad234b113d44ed80a466faf996401.tar.bz2
perlweeklychallenge-club-bc5dc73644cad234b113d44ed80a466faf996401.zip
- Added solutions by E. Choroba.
Diffstat (limited to 'challenge-057')
-rwxr-xr-xchallenge-057/e-choroba/perl/ch-1.pl25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-057/e-choroba/perl/ch-1.pl b/challenge-057/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..5af1aa8245
--- /dev/null
+++ b/challenge-057/e-choroba/perl/ch-1.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+use ARGV::OrDATA;
+
+use FindBin;
+use lib $FindBin::Bin;
+use Tree qw{ from_structure };
+
+sub invert {
+ my ($node, $tree) = @_;
+ return $node unless exists $tree->{$node};
+
+ my @ch = reverse @{ $tree->{$node} };
+ return $node . '(' . join(',', map invert($_, $tree), @ch) . ')'
+}
+
+chomp( my $structure = <> );
+my ($root, $tree) = from_structure($structure);
+say '(', invert($root, $tree), ')';
+
+__DATA__
+(1(2(4,5),3(6,7)))