aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-04-23 16:36:51 +0100
committerGitHub <noreply@github.com>2024-04-23 16:36:51 +0100
commit45ab012ce403904252616a7237dc1d451c7064de (patch)
tree483c45493a0ea40df32dbbf7ad40e6017b439c72
parent705fa6a401e9ecd089fb55e0cb45df905bbfd1bf (diff)
parent81d6fff3c2e69e0435005908cb716deb24c70c02 (diff)
downloadperlweeklychallenge-club-45ab012ce403904252616a7237dc1d451c7064de.tar.gz
perlweeklychallenge-club-45ab012ce403904252616a7237dc1d451c7064de.tar.bz2
perlweeklychallenge-club-45ab012ce403904252616a7237dc1d451c7064de.zip
Merge pull request #9975 from zapwai/branch-for-266
Week 266
-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/perl/ch-1.pl46
-rw-r--r--challenge-265/zapwai/c/ch-2.c113
-rw-r--r--challenge-265/zapwai/rust/ch-2.rs66
-rw-r--r--challenge-266/zapwai/c/ch-1.c93
-rw-r--r--challenge-266/zapwai/c/ch-2.c44
-rw-r--r--challenge-266/zapwai/javascript/ch-1.js42
-rw-r--r--challenge-266/zapwai/javascript/ch-2.js38
-rw-r--r--challenge-266/zapwai/perl/ch-1.pl35
-rw-r--r--challenge-266/zapwai/perl/ch-2.pl38
-rw-r--r--challenge-266/zapwai/python/ch-1.py35
-rw-r--r--challenge-266/zapwai/python/ch-2.py41
-rw-r--r--challenge-266/zapwai/rust/ch-1.rs44
-rw-r--r--challenge-266/zapwai/rust/ch-2.rs52
18 files changed, 747 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/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-265/zapwai/c/ch-2.c b/challenge-265/zapwai/c/ch-2.c
new file mode 100644
index 0000000000..a1e74ec231
--- /dev/null
+++ b/challenge-265/zapwai/c/ch-2.c
@@ -0,0 +1,113 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdbool.h>
+
+typedef struct {
+ char* key;
+ int value;
+} item;
+
+item* val(item* items, size_t size, char* key) {
+ for (size_t i = 0; i < size; i++)
+ if (strcmp(items[i].key, key) == 0)
+ return &items[i];
+ return NULL;
+}
+
+void insert(item* items, size_t size, char* key, int val) {
+ int cnt = 0;
+ for (size_t i = 0; i < size; i++) {
+ if (strcmp(items[i].key, key) == 0) {
+ items[i].value = val;
+ break;
+ }
+ cnt++;
+ }
+ if (cnt == size) {
+ items[size].key = key;
+ items[size].value = val;
+ }
+}
+
+item* freq(char* stringy, int *size) {
+ item* f = malloc(100 * sizeof(item));
+ size_t f_size = 0;
+ for (int i = 0; i < strlen(stringy); i++) {
+ char letter = stringy[i];
+ if (isalpha(letter)) {
+ char let = tolower(letter);
+ item* cell = val(f, f_size, &let);
+ if (!cell) {
+ insert(f, f_size, &let, 1);
+ f_size++;
+ } else {
+ insert(f, f_size, &let, cell->value + 1);
+ }
+ }
+ }
+ *size = f_size;
+ return f;
+}
+
+// Return true if g contains f
+bool hash_contains(item* g, item* f, int g_size, int f_size) {
+ int cnt = 0;
+ for (int i = 0; i < f_size; i++) {
+ char* key = f[i].key;
+ item* gcell = val(g, g_size, key);
+ if (!gcell) {
+ return false;
+ } else {
+ item* fcell = val(f, f_size, key);
+ if (fcell->value <= gcell->value)
+ cnt++;
+ }
+ }
+ return (cnt == f_size);
+}
+
+void proc(char* stringy, char* strlist[], int slen) {
+ printf("Input: str = %s\n \tlist: ", stringy);
+ char* ans[slen];
+ int len = 0;
+ for (int i = 0; i < slen; i++) {
+ ans[i] = NULL;
+ int f_size = 0;
+ int g_size = 0;
+ if (hash_contains(freq(strlist[i], &g_size), freq(stringy, &f_size), g_size, f_size)) {
+ ans[len] = malloc(30 * sizeof(char));
+ strcpy(ans[len], strlist[i]);
+ len++;
+ }
+ printf("%s ", strlist[i]);
+ }
+ printf("\n");
+ int min = strlen(ans[0]);
+ char* answer = malloc(sizeof(char) * 30);
+ for (int i = 0; i < len; i++) {
+ if (strlen(ans[i]) < min) {
+ min = strlen(ans[i]);
+ strcpy(answer, ans[i]);
+ }
+ free(ans[i]);
+ }
+ if (len > 0)
+ printf("Output: %s\n", answer);
+ free(answer);
+}
+
+int main() {
+ char* stringy = "aBc 11c";
+ char* strlist[] = {"accbbb", "abc", "abbc"};
+ proc(stringy, strlist, 3);
+
+ stringy = "La1 abc";
+ char* strlist2[] = {"abcl", "baacl", "abaalc"};
+ proc(stringy, strlist2, 3);
+
+ stringy = "JB 007";
+ char* strlist3[] = {"jj", "bb", "bjb"};
+ proc(stringy, strlist3, 3);
+}
diff --git a/challenge-265/zapwai/rust/ch-2.rs b/challenge-265/zapwai/rust/ch-2.rs
new file mode 100644
index 0000000000..fe66eb6285
--- /dev/null
+++ b/challenge-265/zapwai/rust/ch-2.rs
@@ -0,0 +1,66 @@
+use std::collections::HashMap;
+
+fn main() {
+ let mut stringy = "aBc 11c";
+ let mut strlist = vec!["accbbb", "abc", "abbc"];
+ proc(stringy, strlist);
+
+ stringy = "La1 abc";
+ strlist = vec!["abcl", "baacl", "abaalc"];
+ proc(stringy, strlist);
+
+ stringy = "JB 007";
+ strlist = vec!["jj", "bb", "bjb"];
+ proc(stringy, strlist);
+}
+
+fn freq(stringy : &str) -> HashMap<char, i32> {
+ let mut f = HashMap::new();
+ for m in stringy.chars() {
+ if m.is_alphabetic() {
+ let _m = m.to_ascii_lowercase();
+ if f.contains_key(&_m) {
+ f.insert(_m, 1 + f.get(&_m).unwrap());
+ } else {
+ f.insert(_m, 1);
+ }
+ }
+ }
+ println!("f: {:?}", f);
+ return f;
+}
+
+// Return true if g contains f
+fn hash_contains(g :HashMap<char, i32>, f :HashMap<char, i32>) -> bool {
+ let mut cnt = 0;
+ for k in f.keys() {
+ if !g.contains_key(&k) {
+ continue;
+ }
+ if f[k] <= g[k] {
+ cnt += 1;
+ }
+ }
+ return cnt == f.keys().len();
+}
+
+fn proc(stringy : &str, strlist : Vec<&str>) {
+ println!("Input: string = {stringy}");
+ println!("\tlist = {:?}", strlist);
+ let mut ans : Vec<&str> = Vec::new();
+ for s in strlist {
+ if hash_contains(freq(s), freq(stringy)) {
+ ans.push(s);
+ }
+ }
+
+ let mut min = ans[0].len();
+ let mut answer = ans[0];
+ for i in 0 .. ans.len() {
+ if ans[i].len() < min {
+ min = ans[i].len();
+ answer = ans[i];
+ }
+ }
+ println!("Output: {answer}");
+}
diff --git a/challenge-266/zapwai/c/ch-1.c b/challenge-266/zapwai/c/ch-1.c
new file mode 100644
index 0000000000..c5be7d73d1
--- /dev/null
+++ b/challenge-266/zapwai/c/ch-1.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#define MAX 100
+
+void proc(char* line1, char* line2) {
+ char* words[MAX];
+ int level = 0;
+ char* l1 = strdup(line1);
+ char* token = strtok(l1, " ");
+ while (token != NULL) {
+ words[level] = malloc(50*sizeof(char));
+ strcpy(words[level], token);
+ level++;
+ token = strtok(NULL, " ");
+ }
+ char* l2 = strdup(line2);
+ char* token2 = strtok(l2, " ");
+ while (token2 != NULL) {
+ words[level] = malloc(50*sizeof(char));
+ strcpy(words[level], token2);
+ level++;
+ token2 = strtok(NULL, " ");
+ }
+
+ char* sorted[level];
+ for (int i = 0; i < level; i++) {
+ sorted[i] = malloc(50*sizeof(char));
+ strcpy(sorted[i], words[i]);
+ }
+ int cnt = 0;
+ do {
+ cnt = 0;
+ for (int i = 0; i < level - 1; i++) {
+ if (strcmp(sorted[i+1], sorted[i]) > 0) {
+ char* word = sorted[i+1];
+ sorted[i+1] = sorted[i];
+ sorted[i] = word;
+ cnt++;
+ }
+ }
+ } while (cnt != 0);
+
+ bool match_flag = false;
+ char* ans[MAX] = {};
+ int ans_len = 0;
+ for (int i = 0; i < level - 1; i++) {
+ if (match_flag) {
+ if (0 != strcmp(sorted[i], sorted[i+1])) {
+ match_flag = false;
+ }
+ continue;
+ }
+ if (0 == strcmp(sorted[i], sorted[i+1])) {
+ match_flag = true;
+ continue;
+ }
+ ans[ans_len] = malloc(50*sizeof(char));
+ strcpy(ans[ans_len], sorted[i]);
+ ans_len++;
+ }
+ if (!match_flag) {
+ strcpy(ans[ans_len], sorted[level-1]);
+ ans_len++;
+ }
+ for (int i = 0; i < level; i++) {
+ free(words[i]);
+ free(sorted[i]);
+ }
+ printf("Input: line1 = %s, line2 = %s\n", line1, line2);
+ printf("Output: { ");
+ for (int i = 0; i < ans_len; i++) {
+ printf("%s ", ans[i]);
+ free(ans[i]);
+ }
+ printf("}\n");
+}
+
+int main() {
+ char* line1 = "Mango is sweet";
+ char* line2 = "Mango is sour";
+ proc(line1, line2);
+
+ line1 = "Mango Mango";
+ line2 = "Orange";
+ proc(line1, line2);
+
+ line1 = "Mango is Mango";
+ line2 = "Orange is Orange";
+ proc(line1, line2);
+}
+
diff --git a/challenge-266/zapwai/c/ch-2.c b/challenge-266/zapwai/c/ch-2.c
new file mode 100644
index 0000000000..860ac1c451
--- /dev/null
+++ b/challenge-266/zapwai/c/ch-2.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdbool.h>
+
+void proc(int N, int matrix[N][N]) {
+ bool fail = false;
+ printf("Input: matrix = \n");
+ for (int i = 0; i < N; i++) {
+ printf("\t");
+ for (int j = 0; j < N; j++) {
+ printf("%d ", matrix[i][j]);
+ if ((i == j) || (i == N - j - 1)) {
+ if (matrix[i][j] == 0)
+ fail = true;
+ } else {
+ if (matrix[i][j] != 0)
+ fail = true;
+ }
+ }
+ printf("\n");
+ }
+ printf("Output: %s\n", (!fail) ? "True" : "False");
+}
+
+int main() {
+ int matrix[4][4] = { {1, 0, 0, 2},
+ {0, 3, 4, 0},
+ {0, 5, 6, 0},
+ {7, 0, 0, 1},
+ };
+ proc(4, matrix);
+
+ int matrix2[3][3] = { {1, 2, 3},
+ {4, 5, 6},
+ {7, 8, 9},
+ };
+ proc(3, matrix2);
+
+ int matrix3[3][3] = { {1, 0, 2},
+ {0, 3, 0},
+ {4, 0, 5},
+ };
+ proc(3, matrix3);
+}
+
diff --git a/challenge-266/zapwai/javascript/ch-1.js b/challenge-266/zapwai/javascript/ch-1.js
new file mode 100644
index 0000000000..80eb3a08ed
--- /dev/null
+++ b/challenge-266/zapwai/javascript/ch-1.js
@@ -0,0 +1,42 @@
+let line1 = 'Mango is sweet';
+let line2 = 'Mango is sour';
+proc(line1, line2);
+
+line1 = 'Mango Mango';
+line2 = 'Orange';
+proc(line1, line2);
+
+line1 = 'Mango is Mango';
+line2 = 'Orange is Orange';
+proc(line1, line2);
+
+function proc(line1, line2) {
+ let words = [];
+ for (let s of line1.split(" ")) {
+ words.push(s);
+ }
+ for (let s of line2.split(" ")) {
+ words.push(s);
+ }
+ words.sort();
+ let match_flag = false;
+ let ans = [];
+ for (let i = 0; i < words.length; i++) {
+ if (match_flag) {
+ if (words[i] != words[i+1]) {
+ match_flag = false;
+ }
+ continue;
+ }
+ if (words[i] == words[i+1]) {
+ match_flag = true;
+ continue;
+ }
+ ans.push(words[i]);
+ }
+ if (match_flag) {
+ ans.push(words[words.length-1])
+ }
+ console.log("Input: l1 =", line1, "l2 =", line2);
+ console.log("Output:",ans);
+}
diff --git a/challenge-266/zapwai/javascript/ch-2.js b/challenge-266/zapwai/javascript/ch-2.js
new file mode 100644
index 0000000000..abbfbddce5
--- /dev/null
+++ b/challenge-266/zapwai/javascript/ch-2.js
@@ -0,0 +1,38 @@
+function proc(N, matrix) {
+ let fail = false;
+ console.log("Input: matrix =", matrix);
+ for (let i = 0; i < N; i++) {
+ for (let j = 0; j < N; j++) {
+ if ((i == j) || (i == N - j - 1)) {
+ if (matrix[i][j] == 0){
+ fail = true;
+ }
+ } else {
+ if (matrix[i][j] != 0) {
+ fail = true;
+ }
+ }
+ }
+ }
+ let output = !fail ? "True" : "False";
+ console.log("Output:", output);
+}
+
+let matrix = [ [1, 0, 0, 2],
+ [0, 3, 4, 0],
+ [0, 5, 6, 0],
+ [7, 0, 0, 1],
+ ];
+proc(4, matrix);
+
+let matrix2 = [ [1, 2, 3],
+ [4, 5, 6],
+ [7, 8, 9],
+ ];
+proc(3, matrix2);
+
+let matrix3 = [ [1, 0, 2],
+ [0, 3, 0],
+ [4, 0, 5],
+ ];
+proc(3, matrix3);
diff --git a/challenge-266/zapwai/perl/ch-1.pl b/challenge-266/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..851cd2fd89
--- /dev/null
+++ b/challenge-266/zapwai/perl/ch-1.pl
@@ -0,0 +1,35 @@
+use v5.38;
+
+my $line1 = 'Mango is sweet';
+my $line2 = 'Mango is sour';
+proc($line1, $line2);
+
+$line1 = 'Mango Mango';
+$line2 = 'Orange';
+proc($line1, $line2);
+
+$line1 = 'Mango is Mango';
+$line2 = 'Orange is Orange';
+proc($line1, $line2);
+
+sub proc($line1, $line2) {
+ my @words = sort (split(" ", $line1), split(" ", $line2));
+ my $match_flag = 0;
+ my @ans;
+ for my $i (0 .. $#words - 1) {
+ if ($match_flag) {
+ if ($words[$i] ne $words[$i+1]) {
+ $match_flag = 0;
+ }
+ next;
+ }
+ if ($words[$i] eq $words[$i+1]) {
+ $match_flag = 1;
+ next;
+ }
+ push @ans, $words[$i];
+ }
+ push @ans, $words[$#words] unless ($match_flag);
+ say "Input: \$line1 = $line1; \$line2 = $line2";
+ say "Output: @ans";
+}
diff --git a/challenge-266/zapwai/perl/ch-2.pl b/challenge-266/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..a81bb7e10a
--- /dev/null
+++ b/challenge-266/zapwai/perl/ch-2.pl
@@ -0,0 +1,38 @@
+use v5.38;
+my $matrix = [ [1, 0, 0, 2],
+ [0, 3, 4, 0],
+ [0, 5, 6, 0],
+ [7, 0, 0, 1],
+ ];
+proc($matrix);
+
+$matrix = [ [1, 2, 3],
+ [4, 5, 6],
+ [7, 8, 9],
+ ];
+proc($matrix);
+
+$matrix = [ [1, 0, 2],
+ [0, 3, 0],
+ [4, 0, 5],
+ ];
+proc($matrix);
+
+sub proc($matrix) {
+ my $fail = 0;
+ my $N = $#{$matrix};
+ say "Input: matrix = ";
+ for my $i (0 .. $N) {
+ print "\t";
+ for my $j (0 .. $N) {
+ print $$matrix[$i][$j];
+ if (($i == $j) || ($i == $N - $j)) {
+ $fail = 1 unless ($$matrix[$i][$j] != 0);
+ } else {
+ $fail = 1 unless ($$matrix[$i][$j] == 0);
+ }
+ }
+ say "";
+ }
+ say "Output: ", ($fail == 0) ? "True" : "False";
+}
diff --git a/challenge-266/zapwai/python/ch-1.py b/challenge-266/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..e29bdc05c5
--- /dev/null
+++ b/challenge-266/zapwai/python/ch-1.py
@@ -0,0 +1,35 @@
+def proc(line1, line2):
+ words = []
+ for l in line1.split(" "):
+ words.append(l)
+ for l in line2.split(" "):
+ words.append(l)
+ words.sort()
+ match_flag = False
+ ans = []
+ for i in range(len(words) - 1):
+ if match_flag:
+ if words[i] != words[i+1]:
+ match_flag = False
+ continue
+ if words[i] == words[i+1]:
+ match_flag = True
+ continue
+ ans.append(words[i])
+ if not match_flag:
+ ans.append(words[-1])
+ print("Input: line1 =", line1, "line2 =",line2)
+ print("Output: ",ans)
+
+line1 = 'Mango is sweet'
+line2 = 'Mango is sour'
+proc(line1, line2)
+
+line1 = 'Mango Mango'
+line2 = 'Orange'
+proc(line1, line2)
+
+line1 = 'Mango is Mango'
+line2 = 'Orange is Orange'
+proc(line1, line2)
+
diff --git a/challenge-266/zapwai/python/ch-2.py b/challenge-266/zapwai/python/ch-2.py
new file mode 100644
index 0000000000..ac2dce4820
--- /dev/null
+++ b/challenge-266/zapwai/python/ch-2.py
@@ -0,0 +1,41 @@
+def proc(matrix):
+ fail = False
+ N = len(matrix[0])
+ print("Input: matrix = ")
+ for i in range(N):
+ print("\t", end='')
+ for j in range(N):
+ print(matrix[i][j], end='')
+ if (i == j) or (i == N - j - 1):
+ if matrix[i][j] == 0:
+ fail = True
+ else:
+ if matrix[i][j] != 0:
+ fail = True
+ print()
+ output = ""
+ if not fail:
+ output = "True"
+ else:
+ output = "False"
+ print("Output:", output)
+
+matrix = [ [1, 0, 0, 2],
+ [0, 3, 4, 0],
+ [0, 5, 6, 0],
+ [7, 0, 0, 1],
+ ]
+proc(matrix)
+
+matrix = [ [1, 2, 3],
+ [4, 5, 6],
+ [7, 8, 9],
+ ]
+proc(matrix)
+
+matrix = [ [1, 0, 2],
+ [0, 3, 0],
+ [4, 0, 5],
+ ]
+proc(matrix)
+
diff --git a/challenge-266/zapwai/rust/ch-1.rs b/challenge-266/zapwai/rust/ch-1.rs
new file mode 100644
index 0000000000..cdba8458a5
--- /dev/null
+++ b/challenge-266/zapwai/rust/ch-1.rs
@@ -0,0 +1,44 @@
+fn main() {
+ let mut line1 = "Mango is sweet";
+ let mut line2 = "Mango is sour";
+ proc(line1, line2);
+
+ line1 = "Mango Mango";
+ line2 = "Orange";
+ proc(line1, line2);
+
+ line1 = "Mango is Mango";
+ line2 = "Orange is Orange";
+ proc(line1, line2);
+}
+
+fn proc(line1 : &str, line2 : &str) {
+ let mut words :Vec<&str> = Vec::new();
+ for w in line1.split(" ") {
+ words.push(w);
+ }
+ for w in line2.split(" ") {
+ words.push(w);
+ }
+ words.sort();
+ let mut match_flag = false;
+ let mut ans : Vec<&str> = Vec::new();
+ for i in 0 .. words.len() - 1 {
+ if match_flag {
+ if words[i] != words[i+1] {
+ match_flag = false;
+ }
+ continue;
+ }
+ if words[i] == words[i+1] {
+ match_flag = true;
+ continue;
+ }
+ ans.push(words[i]);
+ }
+ if !match_flag {
+ ans.push(words.last().unwrap());
+ }
+ println!("Input: line1 = {line1}; line2 = {line2}");
+ println!("Output: {:?}", ans);
+}
diff --git a/challenge-266/zapwai/rust/ch-2.rs b/challenge-266/zapwai/rust/ch-2.rs
new file mode 100644
index 0000000000..d558e7cdc2
--- /dev/null
+++ b/challenge-266/zapwai/rust/ch-2.rs
@@ -0,0 +1,52 @@
+fn proc(n : i32, matrix : Vec<Vec<i32>>) {
+ let mut fail :bool = false;
+ println!("Input: matrix = ");
+ for i in 0 .. n {
+ print!("\t");
+ for j in 0 .. n {
+ let i_ = i as usize;
+ let j_ = j as usize;
+ print!("{} ", matrix[i_][j_]);
+ if (i == j) || (i == n - j - 1) {
+ if matrix[i_][j_] == 0 {
+ fail = true;
+ }
+ } else {
+ if matrix[i_][j_] != 0 {
+ fail = true;
+ }
+ }
+ }
+ println!();
+ }
+ let mut output : &str;
+ if !fail {
+ output = "True";
+ } else {
+ output = "False";
+ }
+ println!("Output: {}", output);
+}
+
+fn main() {
+ let matrix = vec![
+ vec![1, 0, 0, 2],
+ vec![0, 3, 4, 0],
+ vec![0, 5, 6, 0],
+ vec![7, 0, 0, 1],
+ ];
+ proc(4, matrix);
+
+ let matrix2 = vec![ vec![1, 2, 3],
+ vec![4, 5, 6],
+ vec![7, 8, 9],
+ ];
+ proc(3, matrix2);
+
+ let matrix3 = vec![ vec![1, 0, 2],
+ vec![0, 3, 0],
+ vec![4, 0, 5],
+ ];
+ proc(3, matrix3);
+}
+