aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-017/zapwai/c/ch-1.c15
-rw-r--r--challenge-017/zapwai/javascript/ch-1.js11
-rw-r--r--challenge-017/zapwai/perl/ch-1.pl12
-rw-r--r--challenge-017/zapwai/python/ch-1.py8
-rw-r--r--challenge-017/zapwai/rust/ch-1.rs14
-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
10 files changed, 290 insertions, 0 deletions
diff --git a/challenge-017/zapwai/c/ch-1.c b/challenge-017/zapwai/c/ch-1.c
new file mode 100644
index 0000000000..e5e063ec99
--- /dev/null
+++ b/challenge-017/zapwai/c/ch-1.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int A(int m, int n) {
+ if (m == 0) {
+ return n + 1;
+ } else if (n == 0) {
+ return A(m - 1, 1);
+ } else {
+ return A(m - 1, A(m, n - 1));
+ }
+}
+
+int main() {
+ printf("%d\n", A(1,2));
+}
diff --git a/challenge-017/zapwai/javascript/ch-1.js b/challenge-017/zapwai/javascript/ch-1.js
new file mode 100644
index 0000000000..d2ad0c6bd9
--- /dev/null
+++ b/challenge-017/zapwai/javascript/ch-1.js
@@ -0,0 +1,11 @@
+function A(m, n) {
+ if (m == 0) {
+ return n + 1;
+ } else if (n == 0) {
+ return A(m - 1, 1);
+ } else {
+ return A(m - 1, A(m, n - 1));
+ }
+}
+
+console.log( A(1,2) );
diff --git a/challenge-017/zapwai/perl/ch-1.pl b/challenge-017/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..afa8d4e808
--- /dev/null
+++ b/challenge-017/zapwai/perl/ch-1.pl
@@ -0,0 +1,12 @@
+use v5.38;
+sub A($m, $n) {
+ if ($m == 0) {
+ return $n + 1;
+ } elsif ($n == 0) {
+ return A($m - 1, 1);
+ } else {
+ return A($m - 1, A($m, $n - 1));
+ }
+}
+
+say A(1,2);
diff --git a/challenge-017/zapwai/python/ch-1.py b/challenge-017/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..f3ce8c2cf6
--- /dev/null
+++ b/challenge-017/zapwai/python/ch-1.py
@@ -0,0 +1,8 @@
+def A(m, n):
+ if m == 0:
+ return n + 1
+ elif (n == 0):
+ return A(m - 1, 1)
+ else:
+ return A(m - 1, A(m, n - 1))
+print(A(1,2))
diff --git a/challenge-017/zapwai/rust/ch-1.rs b/challenge-017/zapwai/rust/ch-1.rs
new file mode 100644
index 0000000000..ec3a19eb13
--- /dev/null
+++ b/challenge-017/zapwai/rust/ch-1.rs
@@ -0,0 +1,14 @@
+
+fn A(m :i32, n :i32) -> i32 {
+ if m == 0 {
+ return n + 1;
+ } else if n == 0 {
+ return A(m - 1, 1);
+ } else {
+ return A(m - 1, A(m, n - 1));
+ }
+}
+
+fn main() {
+ println!("{}", A(1,2));
+}
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);