aboutsummaryrefslogtreecommitdiff
path: root/challenge-131
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-09-27 02:41:15 +0100
committerGitHub <noreply@github.com>2021-09-27 02:41:15 +0100
commitcd79ec656404dcbc2def7683c18a336051c779bc (patch)
treef0dc5b5b05289b513f49872af3bf4376a4b676c9 /challenge-131
parent2183951ca27e30c13e933b4d596cb76f213c3b22 (diff)
parentd1fb4db69126b785f9336cfb5bec97f7e976f663 (diff)
downloadperlweeklychallenge-club-cd79ec656404dcbc2def7683c18a336051c779bc.tar.gz
perlweeklychallenge-club-cd79ec656404dcbc2def7683c18a336051c779bc.tar.bz2
perlweeklychallenge-club-cd79ec656404dcbc2def7683c18a336051c779bc.zip
Merge pull request #4927 from Abigail/abigail/week-131
Abigail/week 131
Diffstat (limited to 'challenge-131')
-rw-r--r--challenge-131/abigail/README.md11
-rw-r--r--challenge-131/abigail/awk/ch-1.awk18
-rw-r--r--challenge-131/abigail/awk/ch-2.awk35
-rw-r--r--challenge-131/abigail/blog.txt1
-rw-r--r--challenge-131/abigail/blog1.txt1
-rw-r--r--challenge-131/abigail/c/ch-1.c35
-rw-r--r--challenge-131/abigail/perl/ch-1.pl24
-rw-r--r--challenge-131/abigail/perl/ch-2.pl48
-rw-r--r--challenge-131/abigail/t/ctest.ini9
-rw-r--r--challenge-131/abigail/t/input-1-14
-rw-r--r--challenge-131/abigail/t/input-2-12
-rw-r--r--challenge-131/abigail/t/input-2-22
-rw-r--r--challenge-131/abigail/t/output-1-1.exp10
-rw-r--r--challenge-131/abigail/t/output-2-1.exp2
-rw-r--r--challenge-131/abigail/t/output-2-2.exp2
15 files changed, 204 insertions, 0 deletions
diff --git a/challenge-131/abigail/README.md b/challenge-131/abigail/README.md
index 38e51d0b9c..4c27485f4c 100644
--- a/challenge-131/abigail/README.md
+++ b/challenge-131/abigail/README.md
@@ -1 +1,12 @@
# Solutions by Abigail
+
+## Part 1
+
+* [AWK](awk/ch-1.awk)
+* [C](c/ch-1.c)
+* [Perl](perl/ch-1.pl)
+
+## Part 2
+
+* [AWK](awk/ch-2.awk)
+* [Perl](perl/ch-2.pl)
diff --git a/challenge-131/abigail/awk/ch-1.awk b/challenge-131/abigail/awk/ch-1.awk
new file mode 100644
index 0000000000..bdf93e5a1a
--- /dev/null
+++ b/challenge-131/abigail/awk/ch-1.awk
@@ -0,0 +1,18 @@
+#!/usr/bin/awk
+
+#
+# See ../README.md
+#
+
+#
+# Run as: awk -f ch-1.awk < input-file
+#
+
+{
+ prev = 0
+ for (i = 1; i <= NF; i ++) {
+ printf ("%s%d", prev == 0 ? "" : (prev + 1 == $i) ? " " : "\n",
+ (prev = $i))
+ }
+ printf ("\n")
+}
diff --git a/challenge-131/abigail/awk/ch-2.awk b/challenge-131/abigail/awk/ch-2.awk
new file mode 100644
index 0000000000..5215d94acf
--- /dev/null
+++ b/challenge-131/abigail/awk/ch-2.awk
@@ -0,0 +1,35 @@
+#!/usr/bin/awk
+
+#
+# See ../README.md
+#
+
+#
+# Run as: awk -f ch-2.awk < input-file
+#
+
+NR == 1 {
+ n = split ($0, delims, "")
+}
+
+NR == 2 {
+ m = split ($0, chars, "")
+ out1 = ""
+ out2 = ""
+ for (i = 1; i <= m; i ++) {
+ for (j = 1; j <= n; j += 2) {
+ if (delims [j] == chars [i]) {
+ out1 = out1 delims [j]
+ break
+ }
+ }
+ for (j = 2; j <= n; j += 2) {
+ if (delims [j] == chars [i]) {
+ out2 = out2 delims [j]
+ break
+ }
+ }
+ }
+ print out1
+ print out2
+}
diff --git a/challenge-131/abigail/blog.txt b/challenge-131/abigail/blog.txt
new file mode 100644
index 0000000000..07cc9a6b7e
--- /dev/null
+++ b/challenge-131/abigail/blog.txt
@@ -0,0 +1 @@
+https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-131-1.html
diff --git a/challenge-131/abigail/blog1.txt b/challenge-131/abigail/blog1.txt
new file mode 100644
index 0000000000..d7283fdf2d
--- /dev/null
+++ b/challenge-131/abigail/blog1.txt
@@ -0,0 +1 @@
+https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-131-2.html
diff --git a/challenge-131/abigail/c/ch-1.c b/challenge-131/abigail/c/ch-1.c
new file mode 100644
index 0000000000..783d0f19d3
--- /dev/null
+++ b/challenge-131/abigail/c/ch-1.c
@@ -0,0 +1,35 @@
+# include <stdlib.h>
+# include <stdio.h>
+# include <string.h>
+
+/*
+ * See ../README.md
+ */
+
+/*
+ * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o < input-file
+ */
+
+int main (void) {
+ char * line = NULL;
+ size_t len = 0;
+ size_t str_len;
+
+ while ((str_len = getline (&line, &len, stdin)) != -1) {
+ char * line_ptr = line;
+ int num;
+ int offset;
+ int prev = 0;
+ while (sscanf (line_ptr, "%d%n", &num, &offset) == 1) {
+ printf ("%s%d", prev == 0 ? ""
+ : prev + 1 == num ? " "
+ : "\n", num);
+ prev = num;
+ line_ptr += offset;
+ }
+ printf ("\n");
+ }
+ free (line);
+
+ return (0);
+}
diff --git a/challenge-131/abigail/perl/ch-1.pl b/challenge-131/abigail/perl/ch-1.pl
new file mode 100644
index 0000000000..413c037a86
--- /dev/null
+++ b/challenge-131/abigail/perl/ch-1.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-1.pl < input-file
+#
+
+while (<>) {
+ my $prev = 0;
+ print $prev ? $prev + 1 == $_ ? " " : "\n" : "", $prev = $_ for /[0-9]+/g;
+ print "\n";
+}
diff --git a/challenge-131/abigail/perl/ch-2.pl b/challenge-131/abigail/perl/ch-2.pl
new file mode 100644
index 0000000000..98d45e499b
--- /dev/null
+++ b/challenge-131/abigail/perl/ch-2.pl
@@ -0,0 +1,48 @@
+#!/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
+#
+# First line of input: delimiters
+# Second line of input: string to search
+#
+
+#
+# What a strange way of phrasing the exercise. We're given a string
+# of "delimiter pairs", but we actually have to do nothing at all with
+# the "delimiter" part.
+#
+# Basically, we have two sets of characters which we need to extract
+# from the string, but for some reason, the two sets of characters
+# are interleaved. Weird.
+#
+
+chomp (my $chars = <>);
+$_ = <>; # String to search
+
+#
+# Extract the characters on the odd and even positions;
+# replace / with \/, and \ with \\.
+#
+my $odds = $chars =~ s/(.)./$1/gr =~ s!([/\\])!\\$1!r;
+my $even = $chars =~ s/.(.)/$1/gr =~ s!([/\\])!\\$1!r;
+
+#
+# Use y///dc to get rid of the characters which don't match, and
+# print the remainder.
+#
+say eval "y/$odds//dcr";
+say eval "y/$even//dcr";
diff --git a/challenge-131/abigail/t/ctest.ini b/challenge-131/abigail/t/ctest.ini
new file mode 100644
index 0000000000..d80f333d95
--- /dev/null
+++ b/challenge-131/abigail/t/ctest.ini
@@ -0,0 +1,9 @@
+#
+# Configuration file for running tests, using ctest.
+# See https://github.com/Abigail/Misc/blob/master/ctest
+#
+
+[names]
+1-1 = Given Examples
+2-1 = Given Example 1
+2-2 = Given Example 2
diff --git a/challenge-131/abigail/t/input-1-1 b/challenge-131/abigail/t/input-1-1
new file mode 100644
index 0000000000..2c39068bfe
--- /dev/null
+++ b/challenge-131/abigail/t/input-1-1
@@ -0,0 +1,4 @@
+1 2 3 6 7 8 9
+11 12 14 17 18 19
+2 4 6 8
+1 2 3 4 5
diff --git a/challenge-131/abigail/t/input-2-1 b/challenge-131/abigail/t/input-2-1
new file mode 100644
index 0000000000..204b556340
--- /dev/null
+++ b/challenge-131/abigail/t/input-2-1
@@ -0,0 +1,2 @@
+""[]()
+"I like (parens) and the Apple ][+" they said.
diff --git a/challenge-131/abigail/t/input-2-2 b/challenge-131/abigail/t/input-2-2
new file mode 100644
index 0000000000..61401e591a
--- /dev/null
+++ b/challenge-131/abigail/t/input-2-2
@@ -0,0 +1,2 @@
+**//<>
+/* This is a comment (in some languages) */ <could be a tag>
diff --git a/challenge-131/abigail/t/output-1-1.exp b/challenge-131/abigail/t/output-1-1.exp
new file mode 100644
index 0000000000..b4c41b95b5
--- /dev/null
+++ b/challenge-131/abigail/t/output-1-1.exp
@@ -0,0 +1,10 @@
+1 2 3
+6 7 8 9
+11 12
+14
+17 18 19
+2
+4
+6
+8
+1 2 3 4 5
diff --git a/challenge-131/abigail/t/output-2-1.exp b/challenge-131/abigail/t/output-2-1.exp
new file mode 100644
index 0000000000..dd64ebf4fc
--- /dev/null
+++ b/challenge-131/abigail/t/output-2-1.exp
@@ -0,0 +1,2 @@
+"(["
+")]"
diff --git a/challenge-131/abigail/t/output-2-2.exp b/challenge-131/abigail/t/output-2-2.exp
new file mode 100644
index 0000000000..c6fadda977
--- /dev/null
+++ b/challenge-131/abigail/t/output-2-2.exp
@@ -0,0 +1,2 @@
+/**/<
+/**/>