aboutsummaryrefslogtreecommitdiff
path: root/challenge-018
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2024-04-22 10:47:30 -0400
committerDavid Ferrone <zapwai@gmail.com>2024-04-22 10:47:30 -0400
commitc6d98285b8aa8be2852b9de1cbc1c9f57ded3d3b (patch)
tree563d71cab0db4fb8e4e6ea7d39434342251a4ff8 /challenge-018
parent9e76d8d75b217afd882e2a661709b63766d058be (diff)
downloadperlweeklychallenge-club-c6d98285b8aa8be2852b9de1cbc1c9f57ded3d3b.tar.gz
perlweeklychallenge-club-c6d98285b8aa8be2852b9de1cbc1c9f57ded3d3b.tar.bz2
perlweeklychallenge-club-c6d98285b8aa8be2852b9de1cbc1c9f57ded3d3b.zip
Ancient Challenges
Diffstat (limited to 'challenge-018')
-rw-r--r--challenge-018/zapwai/c/ch-1.c46
-rw-r--r--challenge-018/zapwai/javascript/ch-1.js46
-rw-r--r--challenge-018/zapwai/perl/ch-1.pl46
-rw-r--r--challenge-018/zapwai/python/ch-1.py46
-rw-r--r--challenge-018/zapwai/rust/ch-1.rs46
5 files changed, 230 insertions, 0 deletions
diff --git a/challenge-018/zapwai/c/ch-1.c b/challenge-018/zapwai/c/ch-1.c
new file mode 100644
index 0000000000..d9aa2d1a54
--- /dev/null
+++ b/challenge-018/zapwai/c/ch-1.c
@@ -0,0 +1,46 @@
+use v5.38;
+if (@ARGV < 2) {
+ say "Please provide two (or more) arguments.";
+ exit;
+}
+
+sub gen_substr($word) {
+ my @subs;
+ my $current_length = 1;
+ my $a = -1;
+ do {
+ $a++;
+ if ($a + $current_length > length $word) {
+ $a = 0;
+ $current_length++;
+ }
+ push @subs, substr($word, $a, $current_length);
+ } while ($current_length < length $word);
+ return @subs;
+}
+
+sub common(@list) {
+ my $ans;
+ my @subs;
+ for my $i (0 .. $#list) {
+ push @subs, gen_substr($list[$i]);
+ }
+ my @common;
+ for my $i (0 .. $#subs) {
+ for my $j (0 .. $#subs) {
+ next if ($i == $j);
+ push @common, $subs[$i] if ($subs[$i] eq $subs[$j]);
+ }
+ }
+ my $max = 0;
+ my $ans_word;
+ for my $word (@common) {
+ if (length $word > $max) {
+ $max = length $word;
+ $ans_word = $word;
+ }
+ }
+ return $ans_word;
+}
+
+say common(@ARGV);
diff --git a/challenge-018/zapwai/javascript/ch-1.js b/challenge-018/zapwai/javascript/ch-1.js
new file mode 100644
index 0000000000..d9aa2d1a54
--- /dev/null
+++ b/challenge-018/zapwai/javascript/ch-1.js
@@ -0,0 +1,46 @@
+use v5.38;
+if (@ARGV < 2) {
+ say "Please provide two (or more) arguments.";
+ exit;
+}
+
+sub gen_substr($word) {
+ my @subs;
+ my $current_length = 1;
+ my $a = -1;
+ do {
+ $a++;
+ if ($a + $current_length > length $word) {
+ $a = 0;
+ $current_length++;
+ }
+ push @subs, substr($word, $a, $current_length);
+ } while ($current_length < length $word);
+ return @subs;
+}
+
+sub common(@list) {
+ my $ans;
+ my @subs;
+ for my $i (0 .. $#list) {
+ push @subs, gen_substr($list[$i]);
+ }
+ my @common;
+ for my $i (0 .. $#subs) {
+ for my $j (0 .. $#subs) {
+ next if ($i == $j);
+ push @common, $subs[$i] if ($subs[$i] eq $subs[$j]);
+ }
+ }
+ my $max = 0;
+ my $ans_word;
+ for my $word (@common) {
+ if (length $word > $max) {
+ $max = length $word;
+ $ans_word = $word;
+ }
+ }
+ return $ans_word;
+}
+
+say common(@ARGV);
diff --git a/challenge-018/zapwai/perl/ch-1.pl b/challenge-018/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..d9aa2d1a54
--- /dev/null
+++ b/challenge-018/zapwai/perl/ch-1.pl
@@ -0,0 +1,46 @@
+use v5.38;
+if (@ARGV < 2) {
+ say "Please provide two (or more) arguments.";
+ exit;
+}
+
+sub gen_substr($word) {
+ my @subs;
+ my $current_length = 1;
+ my $a = -1;
+ do {
+ $a++;
+ if ($a + $current_length > length $word) {
+ $a = 0;
+ $current_length++;
+ }
+ push @subs, substr($word, $a, $current_length);
+ } while ($current_length < length $word);
+ return @subs;
+}
+
+sub common(@list) {
+ my $ans;
+ my @subs;
+ for my $i (0 .. $#list) {
+ push @subs, gen_substr($list[$i]);
+ }
+ my @common;
+ for my $i (0 .. $#subs) {
+ for my $j (0 .. $#subs) {
+ next if ($i == $j);
+ push @common, $subs[$i] if ($subs[$i] eq $subs[$j]);
+ }
+ }
+ my $max = 0;
+ my $ans_word;
+ for my $word (@common) {
+ if (length $word > $max) {
+ $max = length $word;
+ $ans_word = $word;
+ }
+ }
+ return $ans_word;
+}
+
+say common(@ARGV);
diff --git a/challenge-018/zapwai/python/ch-1.py b/challenge-018/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..d9aa2d1a54
--- /dev/null
+++ b/challenge-018/zapwai/python/ch-1.py
@@ -0,0 +1,46 @@
+use v5.38;
+if (@ARGV < 2) {
+ say "Please provide two (or more) arguments.";
+ exit;
+}
+
+sub gen_substr($word) {
+ my @subs;
+ my $current_length = 1;
+ my $a = -1;
+ do {
+ $a++;
+ if ($a + $current_length > length $word) {
+ $a = 0;
+ $current_length++;
+ }
+ push @subs, substr($word, $a, $current_length);
+ } while ($current_length < length $word);
+ return @subs;
+}
+
+sub common(@list) {
+ my $ans;
+ my @subs;
+ for my $i (0 .. $#list) {
+ push @subs, gen_substr($list[$i]);
+ }
+ my @common;
+ for my $i (0 .. $#subs) {
+ for my $j (0 .. $#subs) {
+ next if ($i == $j);
+ push @common, $subs[$i] if ($subs[$i] eq $subs[$j]);
+ }
+ }
+ my $max = 0;
+ my $ans_word;
+ for my $word (@common) {
+ if (length $word > $max) {
+ $max = length $word;
+ $ans_word = $word;
+ }
+ }
+ return $ans_word;
+}
+
+say common(@ARGV);
diff --git a/challenge-018/zapwai/rust/ch-1.rs b/challenge-018/zapwai/rust/ch-1.rs
new file mode 100644
index 0000000000..d9aa2d1a54
--- /dev/null
+++ b/challenge-018/zapwai/rust/ch-1.rs
@@ -0,0 +1,46 @@
+use v5.38;
+if (@ARGV < 2) {
+ say "Please provide two (or more) arguments.";
+ exit;
+}
+
+sub gen_substr($word) {
+ my @subs;
+ my $current_length = 1;
+ my $a = -1;
+ do {
+ $a++;
+ if ($a + $current_length > length $word) {
+ $a = 0;
+ $current_length++;
+ }
+ push @subs, substr($word, $a, $current_length);
+ } while ($current_length < length $word);
+ return @subs;
+}
+
+sub common(@list) {
+ my $ans;
+ my @subs;
+ for my $i (0 .. $#list) {
+ push @subs, gen_substr($list[$i]);
+ }
+ my @common;
+ for my $i (0 .. $#subs) {
+ for my $j (0 .. $#subs) {
+ next if ($i == $j);
+ push @common, $subs[$i] if ($subs[$i] eq $subs[$j]);
+ }
+ }
+ my $max = 0;
+ my $ans_word;
+ for my $word (@common) {
+ if (length $word > $max) {
+ $max = length $word;
+ $ans_word = $word;
+ }
+ }
+ return $ans_word;
+}
+
+say common(@ARGV);