aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-05-10 09:56:20 +0200
committerAbigail <abigail@abigail.be>2021-05-10 09:56:20 +0200
commitad6243d65f3989322281f49c60264a38f10b7961 (patch)
tree0b9c5b1e2692297e23a3be9ccbb2a505b62283d0
parent5e4bc741d5ce6a37db6a72c3845ba4caefae1b6b (diff)
downloadperlweeklychallenge-club-ad6243d65f3989322281f49c60264a38f10b7961.tar.gz
perlweeklychallenge-club-ad6243d65f3989322281f49c60264a38f10b7961.tar.bz2
perlweeklychallenge-club-ad6243d65f3989322281f49c60264a38f10b7961.zip
Perl solutions for week 112
-rw-r--r--challenge-112/abigail/perl/ch-1.pl43
-rw-r--r--challenge-112/abigail/perl/ch-2.pl24
2 files changed, 67 insertions, 0 deletions
diff --git a/challenge-112/abigail/perl/ch-1.pl b/challenge-112/abigail/perl/ch-1.pl
new file mode 100644
index 0000000000..e1f01db484
--- /dev/null
+++ b/challenge-112/abigail/perl/ch-1.pl
@@ -0,0 +1,43 @@
+#!/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-1.pl < input-file
+#
+
+while (<>) {
+ chomp;
+
+ # Remove duplicate slashes
+ s !/\K/+!!g;
+
+ # Add a trailing slash; this makes it easier to deal
+ # with the cases below.
+ $_ .= "/";
+
+ # Remove single period
+ s !/\.(?=/)!!g;
+
+ # Remove double period
+ 1 while s !/[^/]+/\.\.(?=/)!!;
+
+ # Remove any leading /../
+ 1 while s !^/\.\./!/!;
+
+ # Remove trailing slashes
+ s !/+$!!;
+
+ say;
+}
diff --git a/challenge-112/abigail/perl/ch-2.pl b/challenge-112/abigail/perl/ch-2.pl
new file mode 100644
index 0000000000..2d52916053
--- /dev/null
+++ b/challenge-112/abigail/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#!/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
+#
+
+#
+# This is just the Fibonacci numbers...
+#
+sub f ($n) {state $c = {0 => 1, 1 => 1}; $$c {$n} //= f ($n - 1) + f ($n - 2)}
+say f ($_) for <>;