aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-10-23 00:54:11 +0100
committerGitHub <noreply@github.com>2023-10-23 00:54:11 +0100
commite6f79a51177cbbdf78f7bab5f2e0a86073e1fe77 (patch)
tree58152daa22acb69c8556e1b238cf28e121f729d2
parent5b6989a1050a30114a51057b5df747a36cb8c0f2 (diff)
parentc633d3cc588e25e113a69fbc9d8b4c894c834bc8 (diff)
downloadperlweeklychallenge-club-e6f79a51177cbbdf78f7bab5f2e0a86073e1fe77.tar.gz
perlweeklychallenge-club-e6f79a51177cbbdf78f7bab5f2e0a86073e1fe77.tar.bz2
perlweeklychallenge-club-e6f79a51177cbbdf78f7bab5f2e0a86073e1fe77.zip
Merge pull request #8912 from polettix/polettix/pwc239
Add polettix's solution to challenge-239
-rw-r--r--challenge-239/polettix/blog.txt1
-rw-r--r--challenge-239/polettix/blog1.txt1
-rw-r--r--challenge-239/polettix/perl/ch-1.pl36
-rw-r--r--challenge-239/polettix/perl/ch-2.pl17
-rw-r--r--challenge-239/polettix/raku/ch-1.raku5
-rw-r--r--challenge-239/polettix/raku/ch-2.raku14
6 files changed, 74 insertions, 0 deletions
diff --git a/challenge-239/polettix/blog.txt b/challenge-239/polettix/blog.txt
new file mode 100644
index 0000000000..694557e19b
--- /dev/null
+++ b/challenge-239/polettix/blog.txt
@@ -0,0 +1 @@
+https://etoobusy.polettix.it/2023/10/22/pwc239-same-string/
diff --git a/challenge-239/polettix/blog1.txt b/challenge-239/polettix/blog1.txt
new file mode 100644
index 0000000000..8c4c2dc3a6
--- /dev/null
+++ b/challenge-239/polettix/blog1.txt
@@ -0,0 +1 @@
+https://etoobusy.polettix.it/2023/10/23/consistent-strings/
diff --git a/challenge-239/polettix/perl/ch-1.pl b/challenge-239/polettix/perl/ch-1.pl
new file mode 100644
index 0000000000..9fdca746f8
--- /dev/null
+++ b/challenge-239/polettix/perl/ch-1.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl
+use v5.24;
+use warnings;
+
+my ($s1, $s2) = map { [ split m{,}mxs ] } @ARGV[0,1];
+say is_same_string($s1, $s2) ? 'true' : 'false';
+
+sub is_same_string {
+ my ($lead, @other) = map {
+ my $aref = $_;
+ my $idx = 0;
+ my $ch_idx = 0;
+ sub {
+ while ($idx <= $aref->$#*) {
+ return substr($aref->[$idx], $ch_idx++, 1)
+ if $ch_idx < length($aref->[$idx]);
+ ++$idx;
+ $ch_idx = 0;
+ }
+ return;
+ };
+ } @_;
+ while ('necessary') {
+ my $ch = $lead->();
+ if (! defined($ch)) {
+ for my $it (@other) {
+ return 0 if defined($it->());
+ }
+ return 1;
+ }
+ for my $it (@other) {
+ my $och = $it->();
+ return 0 if ($och // '') ne $ch;
+ }
+ }
+}
diff --git a/challenge-239/polettix/perl/ch-2.pl b/challenge-239/polettix/perl/ch-2.pl
new file mode 100644
index 0000000000..b84db571a4
--- /dev/null
+++ b/challenge-239/polettix/perl/ch-2.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+use v5.24;
+use warnings;
+use experimental 'signatures';
+
+my $cc = consistency_checker_for(shift);
+say scalar grep { $cc->($_) } @ARGV;
+
+sub consistency_checker_for ($string) {
+ my %is_allowed = map { $_ => 1 } split m{}mxs, shift;
+ return sub ($input) {
+ for my $i (0 .. length($input) - 1) {
+ return unless $is_allowed{substr($input, $i, 1)};
+ }
+ return 1;
+ };
+}
diff --git a/challenge-239/polettix/raku/ch-1.raku b/challenge-239/polettix/raku/ch-1.raku
new file mode 100644
index 0000000000..6da69f3bfb
--- /dev/null
+++ b/challenge-239/polettix/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/usr/bin/env raku
+use v6;
+sub MAIN ($s1, $s2) { say is-same-string($s1.split(/\,/), $s2.split(/\,/)) }
+
+sub is-same-string (@s1, @s2) { @s1.join('') eq @s2.join('') }
diff --git a/challenge-239/polettix/raku/ch-2.raku b/challenge-239/polettix/raku/ch-2.raku
new file mode 100644
index 0000000000..068f44876e
--- /dev/null
+++ b/challenge-239/polettix/raku/ch-2.raku
@@ -0,0 +1,14 @@
+#!/usr/bin/env raku
+use v6;
+sub MAIN ($allowed, *@str) { put consistent-string($allowed, @str).elems }
+
+sub consistent-string ($allowed, @str) {
+ my $al = $allowed.comb.Set;
+ my &checker = sub ($input) {
+ for $input.comb -> $c {
+ return False unless $c ∈ $al;
+ }
+ return True;
+ };
+ @str.grep(&checker);
+}