aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-22 15:48:26 +0100
committerGitHub <noreply@github.com>2024-07-22 15:48:26 +0100
commit8076b99050fc0e225159b49fbff5207c7ff60394 (patch)
tree83981880cb79685efd0b1e2915daa94fb64b6270
parent7f5df092b84ed9b8126a7f3ab334adc2a54cf63d (diff)
parent6dad2b4f822afe167c59329b2493635db6809a2b (diff)
downloadperlweeklychallenge-club-8076b99050fc0e225159b49fbff5207c7ff60394.tar.gz
perlweeklychallenge-club-8076b99050fc0e225159b49fbff5207c7ff60394.tar.bz2
perlweeklychallenge-club-8076b99050fc0e225159b49fbff5207c7ff60394.zip
Merge pull request #10479 from zapwai/branch-for-279
Week 279
-rw-r--r--challenge-279/zapwai/c/ch-1.c30
-rw-r--r--challenge-279/zapwai/c/ch-2.c37
-rw-r--r--challenge-279/zapwai/javascript/ch-1.js18
-rw-r--r--challenge-279/zapwai/javascript/ch-2.js33
-rw-r--r--challenge-279/zapwai/perl/ch-1.pl20
-rw-r--r--challenge-279/zapwai/perl/ch-2.pl14
-rw-r--r--challenge-279/zapwai/python/ch-1.py18
-rw-r--r--challenge-279/zapwai/python/ch-2.py24
-rw-r--r--challenge-279/zapwai/rust/ch-1.rs23
-rw-r--r--challenge-279/zapwai/rust/ch-2.rs36
10 files changed, 253 insertions, 0 deletions
diff --git a/challenge-279/zapwai/c/ch-1.c b/challenge-279/zapwai/c/ch-1.c
new file mode 100644
index 0000000000..9510cf13e5
--- /dev/null
+++ b/challenge-279/zapwai/c/ch-1.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+void proc(char l[], int w[], int llen) {
+ printf("Input: letters = ");
+ for (int i = 0; i < llen; i++)
+ printf("%c ", l[i]);
+ printf(", weights = ");
+ for (int i = 0; i < llen; i++)
+ printf("%d ", w[i]);
+ printf("\n");
+ char ans[llen];
+ for (int i = 0; i < llen; i++)
+ ans[w[i] - 1] = l[i];
+ printf("Output: ");
+ for (int i = 0; i < llen; i++)
+ printf("%c", ans[i]);
+ printf("\n");
+}
+
+int main() {
+ char letters[] = {'R', 'E', 'P', 'L'};
+ int weights[] = {3, 2, 1, 4};
+ proc(letters, weights, sizeof(letters) / sizeof(char));
+ char letters2[] = {'A', 'U', 'R', 'K'};
+ int weights2[] = {2, 4, 1, 3};
+ proc(letters2, weights2, sizeof(letters2) / sizeof(char));
+ char letters3[] = {'O', 'H', 'Y', 'N', 'P', 'T'};
+ int weights3[] = {5, 4, 2, 6, 1, 3};
+ proc(letters3, weights3, sizeof(letters3) / sizeof(char));
+}
diff --git a/challenge-279/zapwai/c/ch-2.c b/challenge-279/zapwai/c/ch-2.c
new file mode 100644
index 0000000000..d9d9f0a20c
--- /dev/null
+++ b/challenge-279/zapwai/c/ch-2.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+bool is_vowel(char c) {
+ if (c == 'a' ||
+ c == 'e' ||
+ c == 'i' ||
+ c == 'o' ||
+ c == 'u')
+ return true;
+ if (c == 'A' ||
+ c == 'E' ||
+ c == 'I' ||
+ c == 'O' ||
+ c == 'U')
+ return true;
+ return false;
+}
+
+void proc(char* str) {
+ printf("Input: str = %s\n", str);
+ int cnt = 0;
+ for (int i = 0; i < strlen(str); i++)
+ if (is_vowel(str[i]))
+ cnt++;
+ printf("Output: %s" , (cnt % 2 == 0) ? " true\n" : " false\n");
+}
+
+int main() {
+ char* str = "perl";
+ proc(str);
+ str = "book";
+ proc(str);
+ str = "goodmorning";
+ proc(str);
+}
diff --git a/challenge-279/zapwai/javascript/ch-1.js b/challenge-279/zapwai/javascript/ch-1.js
new file mode 100644
index 0000000000..90e00128a6
--- /dev/null
+++ b/challenge-279/zapwai/javascript/ch-1.js
@@ -0,0 +1,18 @@
+let letters = ['R', 'E', 'P', 'L'];
+let weights = [3, 2, 1, 4];
+proc(letters, weights);
+letters = ['A', 'U', 'R', 'K'];
+weights = [2, 4, 1, 3];
+proc(letters, weights);
+letters = ['O', 'H', 'Y', 'N', 'P', 'T'];
+weights = [5, 4, 2, 6, 1, 3];
+proc(letters, weights);
+
+function proc(l, w) {
+ console.log("Input: letters, weights", l, w);
+ let ans = [];
+ for (let i = 0; i < l.length; i++) {
+ ans[w[i] - 1] = l[i];
+ }
+ console.log("Output: ", ans);
+}
diff --git a/challenge-279/zapwai/javascript/ch-2.js b/challenge-279/zapwai/javascript/ch-2.js
new file mode 100644
index 0000000000..dab758c64e
--- /dev/null
+++ b/challenge-279/zapwai/javascript/ch-2.js
@@ -0,0 +1,33 @@
+let str = "perl";
+proc(str);
+str = "book";
+proc(str);
+str = "goodmorning";
+proc(str);
+
+function is_vowel(c) {
+ if (c == 'a' ||
+ c == 'e' ||
+ c == 'i' ||
+ c == 'o' ||
+ c == 'u') {
+ return true;
+ }
+ return false;
+}
+
+function proc(str) {
+ console.log("Input: str = ", str);
+ let cnt = 0;
+ for (let c of str) {
+ if (is_vowel(c)) {
+ cnt++;
+ }
+ }
+ if (cnt % 2 == 0) {
+ console.log("Output: true");
+ } else {
+ console.log("Output: false");
+ }
+}
+
diff --git a/challenge-279/zapwai/perl/ch-1.pl b/challenge-279/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..a7e0e7947b
--- /dev/null
+++ b/challenge-279/zapwai/perl/ch-1.pl
@@ -0,0 +1,20 @@
+use v5.38;
+my @letters = ('R', 'E', 'P', 'L');
+my @weights = (3, 2, 1, 4);
+proc(\@letters, \@weights);
+@letters = ('A', 'U', 'R', 'K');
+@weights = (2, 4, 1, 3);
+proc(\@letters, \@weights);
+@letters = ('O', 'H', 'Y', 'N', 'P', 'T');
+@weights = (5, 4, 2, 6, 1, 3);
+proc(\@letters, \@weights);
+
+sub proc($l, $w) {
+ say "Input: \@letters = @$l, \@weights = @$w";
+ my $N = scalar @$l;
+ my @ans = ("") x $N;
+ for my $i (0 .. $N - 1) {
+ $ans[$$w[$i] - 1] = $$l[$i];
+ }
+ say "Output: ", @ans;
+}
diff --git a/challenge-279/zapwai/perl/ch-2.pl b/challenge-279/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..31f7c3672a
--- /dev/null
+++ b/challenge-279/zapwai/perl/ch-2.pl
@@ -0,0 +1,14 @@
+use v5.38;
+my $str = "perl";
+proc($str);
+$str = "book";
+proc($str);
+$str = "goodmorning";
+proc($str);
+
+sub proc($str) {
+ say "Input: \$str = $str";
+ my $cnt = grep { $_ =~ /[aeiou]/ } (split "", lc $str);
+ say "Output:" , ($cnt % 2 == 0) ? " true" : " false";
+}
+
diff --git a/challenge-279/zapwai/python/ch-1.py b/challenge-279/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..7490c50a5f
--- /dev/null
+++ b/challenge-279/zapwai/python/ch-1.py
@@ -0,0 +1,18 @@
+def proc(l, w):
+ print("Input: letters =", l, "weights =", w)
+ ans = []
+ for i in range(len(l)):
+ ans.append("")
+ for i in range(len(l)):
+ ans[w[i] - 1] = l[i]
+ print("Output: ", ans)
+
+letters = ['R', 'E', 'P', 'L']
+weights = [3, 2, 1, 4]
+proc(letters, weights)
+letters = ['A', 'U', 'R', 'K']
+weights = [2, 4, 1, 3]
+proc(letters, weights)
+letters = ['O', 'H', 'Y', 'N', 'P', 'T']
+weights = [5, 4, 2, 6, 1, 3]
+proc(letters, weights)
diff --git a/challenge-279/zapwai/python/ch-2.py b/challenge-279/zapwai/python/ch-2.py
new file mode 100644
index 0000000000..b8b25daeeb
--- /dev/null
+++ b/challenge-279/zapwai/python/ch-2.py
@@ -0,0 +1,24 @@
+def is_vowel(c):
+ if c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u':
+ return True
+ return False
+
+def proc(mystr):
+ print("Input: mystr =", mystr)
+ cnt = 0
+ for c in list(mystr):
+ if is_vowel(c):
+ cnt += 1
+
+ if cnt % 2 == 0:
+ print("Output: true")
+ else:
+ print("Output: false")
+
+mystr = "perl"
+proc(mystr)
+mystr = "book"
+proc(mystr)
+mystr = "goodmorning"
+proc(mystr)
+
diff --git a/challenge-279/zapwai/rust/ch-1.rs b/challenge-279/zapwai/rust/ch-1.rs
new file mode 100644
index 0000000000..bd00019eb3
--- /dev/null
+++ b/challenge-279/zapwai/rust/ch-1.rs
@@ -0,0 +1,23 @@
+fn main() {
+ let letters = vec!['R', 'E', 'P', 'L'];
+ let weights = vec![3, 2, 1, 4];
+ proc(letters, weights);
+ let letters2 = vec!['A', 'U', 'R', 'K'];
+ let weights2 = vec![2, 4, 1, 3];
+ proc(letters2, weights2);
+ let letters3 = vec!['O', 'H', 'Y', 'N', 'P', 'T'];
+ let weights3 = vec![5, 4, 2, 6, 1, 3];
+ proc(letters3, weights3);
+}
+
+fn proc(l : Vec<char>, w : Vec<i32>) {
+ println!("Input: letters = {:?}, weights = {:?}", l, w);
+ let mut ans : Vec<char> = Vec::new();
+ for _i in 0 .. l.len() {
+ ans.push(' ');
+ }
+ for i in 0 .. l.len() {
+ ans[(w[i] - 1) as usize] = l[i];
+ }
+ println!("Output: {:?}", ans);
+}
diff --git a/challenge-279/zapwai/rust/ch-2.rs b/challenge-279/zapwai/rust/ch-2.rs
new file mode 100644
index 0000000000..c601369f01
--- /dev/null
+++ b/challenge-279/zapwai/rust/ch-2.rs
@@ -0,0 +1,36 @@
+fn main() {
+ let str = "perl";
+ proc(str);
+ let str2 = "book";
+ proc(str2);
+ let str3 = "goodmorning";
+ proc(str3);
+}
+
+fn is_vowel(c: char) -> bool {
+ if c == 'a' ||
+ c == 'e' ||
+ c == 'i' ||
+ c == 'o' ||
+ c == 'u' {
+ return true;
+ }
+ return false;
+}
+
+fn proc(str : &str) {
+ println!("Input: str = {str}");
+ let mut cnt = 0;
+ for c in str.chars() {
+ if is_vowel(c) {
+ cnt += 1;
+ }
+ }
+ print!("Output:");
+ if cnt % 2 == 0 {
+ println!(" true");
+ } else {
+ println!(" false");
+ }
+}
+