aboutsummaryrefslogtreecommitdiff
path: root/challenge-102/abigail/perl/ch-2.pl
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-102/abigail/perl/ch-2.pl')
-rw-r--r--challenge-102/abigail/perl/ch-2.pl41
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-102/abigail/perl/ch-2.pl b/challenge-102/abigail/perl/ch-2.pl
new file mode 100644
index 0000000000..3073f155a8
--- /dev/null
+++ b/challenge-102/abigail/perl/ch-2.pl
@@ -0,0 +1,41 @@
+#!/opt/perl/bin/perl
+
+use 5.032;
+
+use strict;
+use warnings;
+no warnings 'syntax';
+
+use experimental 'signatures';
+use experimental 'lexical_subs';
+
+#
+# See ../README.md
+#
+
+#
+# Run as: perl ch-2.pl < input-file
+#
+
+#
+# Working from the end of the required string backwards, we alternate
+# placing a hash, and placing a number. We place them in an array @out,
+# and at the end, print out said array in reverse order.
+#
+
+while (my $index = <>) {
+ chomp $index;
+ my @out;
+ my $hash = 0;
+ while ($index) {
+ if ($hash = !$hash) {
+ push @out => "#";
+ $index --;
+ }
+ else {
+ push @out => $index + 1;
+ $index -= length ($index + 1);
+ }
+ }
+ say join "" => reverse @out;
+}