aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-06-11 12:55:01 +0100
committerGitHub <noreply@github.com>2024-06-11 12:55:01 +0100
commitb62ded51075dde53bac2ba4ac7de6089c4996241 (patch)
tree3d1895b2b61dfedb62a57c0654b2d7dbdad5dc92
parent2eace0f9656e6e88ddc9418cc39adb9f57fc5cc1 (diff)
parent2243e21438f7c7a143e6873f8bafa21835d6db69 (diff)
downloadperlweeklychallenge-club-b62ded51075dde53bac2ba4ac7de6089c4996241.tar.gz
perlweeklychallenge-club-b62ded51075dde53bac2ba4ac7de6089c4996241.tar.bz2
perlweeklychallenge-club-b62ded51075dde53bac2ba4ac7de6089c4996241.zip
Merge pull request #10243 from zapwai/branch-for-273
Week 273
-rw-r--r--challenge-273/zapwai/c/ch-1.c32
-rw-r--r--challenge-273/zapwai/c/ch-2.c41
-rw-r--r--challenge-273/zapwai/javascript/ch-1.js24
-rw-r--r--challenge-273/zapwai/javascript/ch-2.js36
-rw-r--r--challenge-273/zapwai/perl/ch-1.pl22
-rw-r--r--challenge-273/zapwai/perl/ch-2.pl29
-rw-r--r--challenge-273/zapwai/python/ch-1.py26
-rw-r--r--challenge-273/zapwai/python/ch-2.py29
-rw-r--r--challenge-273/zapwai/rust/ch-1.rs26
-rw-r--r--challenge-273/zapwai/rust/ch-2.rs38
10 files changed, 303 insertions, 0 deletions
diff --git a/challenge-273/zapwai/c/ch-1.c b/challenge-273/zapwai/c/ch-1.c
new file mode 100644
index 0000000000..ee9a057bc9
--- /dev/null
+++ b/challenge-273/zapwai/c/ch-1.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <string.h>
+
+void proc(char* mystr, char mychar) {
+ printf( "Input: str = %s, char = %c\n", mystr, mychar);
+ int cnt = 0;
+ for (int i = 0; i < strlen(mystr); i++)
+ if (mystr[i] == mychar)
+ cnt++;
+ int inty = 100*((float) cnt / strlen(mystr));
+ float r = 100*((float) cnt / strlen(mystr)) - inty;
+ if (r >= .5)
+ inty++;
+ printf("Output: %d\n", inty);
+}
+
+int main() {
+ char* mystr = "perl";
+ char mychar = 'e';
+ proc(mystr, mychar);
+ mystr = "java"; mychar = 'a';
+ proc(mystr, mychar);
+ mystr = "python"; mychar = 'm';
+ proc(mystr, mychar);
+ mystr = "ada"; mychar = 'a';
+ proc(mystr, mychar);
+ mystr = "ballerina"; mychar = 'l';
+ proc(mystr, mychar);
+ mystr = "analitik"; mychar = 'k';
+ proc(mystr, mychar);
+}
+
diff --git a/challenge-273/zapwai/c/ch-2.c b/challenge-273/zapwai/c/ch-2.c
new file mode 100644
index 0000000000..832af95751
--- /dev/null
+++ b/challenge-273/zapwai/c/ch-2.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+void proc(char* str) {
+ printf( "Input: str = %s\n", str);
+ bool ver = false;
+ int bcnt = 0;
+ for (int i = 0; i <= strlen(str); i++)
+ if (str[i] == 'b')
+ bcnt++;
+ if (bcnt > 0) {
+ ver = true;
+ bool bflag = false;
+ for (int i = 0; i <= strlen(str); i++) {
+ char l = str[i];
+ if ((l == 'a') && bflag) {
+ ver = false;
+ break;
+ } else {
+ if (l == 'b')
+ bflag = true;
+ }
+ }
+ }
+ printf( "Output: ");
+ printf((ver) ? "true" : "false");
+ printf("\n");
+}
+
+int main() {
+ char* str = "aabb";
+ proc(str);
+ str = "abab";
+ proc(str);
+ str = "aaa";
+ proc(str);
+ str = "bbb";
+ proc(str);
+}
+
diff --git a/challenge-273/zapwai/javascript/ch-1.js b/challenge-273/zapwai/javascript/ch-1.js
new file mode 100644
index 0000000000..403abc52e6
--- /dev/null
+++ b/challenge-273/zapwai/javascript/ch-1.js
@@ -0,0 +1,24 @@
+let mystr = "perl"; let mychar = "e";
+proc(mystr, mychar);
+mystr = "java"; mychar = "a";
+proc(mystr, mychar);
+mystr = "python"; mychar = "m";
+proc(mystr, mychar);
+mystr = "ada"; mychar = "a";
+proc(mystr, mychar);
+mystr = "ballerina"; mychar = "l";
+proc(mystr, mychar);
+mystr = "analitik"; mychar = "k";
+proc(mystr, mychar);
+
+function proc(mystr, mychar) {
+ console.log("Input: mystr =", mystr, "mychar =", mychar);
+ let cnt = 0;
+ for (let l of mystr) {
+ if (l == mychar) {
+ cnt++;
+ }
+ }
+ let i = 100*(cnt / mystr.length);
+ console.log( "Output:", Math.round(i));
+}
diff --git a/challenge-273/zapwai/javascript/ch-2.js b/challenge-273/zapwai/javascript/ch-2.js
new file mode 100644
index 0000000000..24ea47ef22
--- /dev/null
+++ b/challenge-273/zapwai/javascript/ch-2.js
@@ -0,0 +1,36 @@
+let mystr = "aabb";
+proc(mystr);
+mystr = "abab";
+proc(mystr);
+mystr = "aaa";
+proc(mystr);
+mystr = "bbb";
+proc(mystr);
+
+function proc(mystr) {
+ console.log( "Input: mystr =", mystr);
+ let ver = 0;
+ for (let l of mystr) {
+ if (l == 'b') {
+ ver = 1;
+ }
+ }
+ if (ver == 1) {
+ let bflag = 0;
+ for (let l of mystr) {
+ if (l == 'a' && bflag == 1) {
+ ver = 0;
+ break;
+ } else {
+ if (l == 'b') {
+ bflag = 1;
+ }
+ }
+ }
+ }
+ if (ver == 1) {
+ console.log("Output: true");
+ } else {
+ console.log("Output: false");
+ }
+}
diff --git a/challenge-273/zapwai/perl/ch-1.pl b/challenge-273/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..fb63c409c8
--- /dev/null
+++ b/challenge-273/zapwai/perl/ch-1.pl
@@ -0,0 +1,22 @@
+use v5.38;
+my $str = "perl"; my $char = "e";
+proc($str, $char);
+$str = "java"; $char = "a";
+proc($str, $char);
+$str = "python"; $char = "m";
+proc($str, $char);
+$str = "ada"; $char = "a";
+proc($str, $char);
+$str = "ballerina"; $char = "l";
+proc($str, $char);
+$str = "analitik"; $char = "k";
+proc($str, $char);
+
+sub proc($str, $char) {
+ say "Input: \$str = $str, \$char = $char";
+ my $cnt = grep { $_ eq $char } split "", $str;
+ my $i = int 100*($cnt / length $str);
+ my $r = 100*($cnt / length $str) - $i;
+ $i++ if ($r >= .5);
+ say "Output: $i";
+}
diff --git a/challenge-273/zapwai/perl/ch-2.pl b/challenge-273/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..59c0b63e44
--- /dev/null
+++ b/challenge-273/zapwai/perl/ch-2.pl
@@ -0,0 +1,29 @@
+use v5.38;
+my $str = "aabb";
+proc($str);
+$str = "abab";
+proc($str);
+$str = "aaa";
+proc($str);
+$str = "bbb";
+proc($str);
+
+sub proc($str) {
+ say "Input: \$str = $str";
+ my $ver = 0;
+ if ($str =~ /b/) {
+ $ver = 1;
+ my $bflag = 0;
+ for my $l (split "", $str) {
+ if ($l eq "a" and $bflag) {
+ $ver = 0;
+ last;
+ } else {
+ if ($l eq "b") {
+ $bflag = 1;
+ }
+ }
+ }
+ }
+ say "Output: ", $ver ? "true" : "false";
+}
diff --git a/challenge-273/zapwai/python/ch-1.py b/challenge-273/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..0cfe3c56b5
--- /dev/null
+++ b/challenge-273/zapwai/python/ch-1.py
@@ -0,0 +1,26 @@
+def proc(mystr, mychar):
+ print("Input: mystr =",mystr, "mychar =", mychar);
+ cnt = 0
+ for l in list(mystr):
+ if l == mychar:
+ cnt += 1
+ i = 100.0 * (cnt / len(mystr));
+ I = int(i)
+ r = i - I
+ if r >= .5:
+ I += 1;
+ print("Output:", I);
+
+mystr = "perl"; mychar = "e"
+proc(mystr, mychar)
+mystr = "java"; mychar = "a"
+proc(mystr, mychar)
+mystr = "python"; mychar = "m"
+proc(mystr, mychar)
+mystr = "ada"; mychar = "a"
+proc(mystr, mychar)
+mystr = "ballerina"; mychar = "l"
+proc(mystr, mychar)
+mystr = "analitik"; mychar = "k"
+proc(mystr, mychar)
+
diff --git a/challenge-273/zapwai/python/ch-2.py b/challenge-273/zapwai/python/ch-2.py
new file mode 100644
index 0000000000..f749308fd9
--- /dev/null
+++ b/challenge-273/zapwai/python/ch-2.py
@@ -0,0 +1,29 @@
+def proc(mystr):
+ print("Input: mystr =", mystr)
+ ver = False
+ for l in list(mystr):
+ if l == 'b':
+ ver = True
+ if ver:
+ bflag = False
+ for l in list(mystr):
+ if (l == 'a' and bflag):
+ ver = False
+ break
+ else:
+ if (l == "b"):
+ bflag = True
+ if ver:
+ print("Output: true")
+ else:
+ print("Output: false")
+
+mystr = "aabb"
+proc(mystr)
+mystr = "abab"
+proc(mystr)
+mystr = "aaa"
+proc(mystr)
+mystr = "bbb"
+proc(mystr)
+
diff --git a/challenge-273/zapwai/rust/ch-1.rs b/challenge-273/zapwai/rust/ch-1.rs
new file mode 100644
index 0000000000..c1eb8fa555
--- /dev/null
+++ b/challenge-273/zapwai/rust/ch-1.rs
@@ -0,0 +1,26 @@
+fn main() {
+ let mut mystr = "perl"; let mut mychar = 'e';
+ proc(mystr, mychar);
+ mystr = "java"; mychar = 'a';
+ proc(mystr, mychar);
+ mystr = "python"; mychar = 'm';
+ proc(mystr, mychar);
+ mystr = "ada"; mychar = 'a';
+ proc(mystr, mychar);
+ mystr = "ballerina"; mychar = 'l';
+ proc(mystr, mychar);
+ mystr = "analitik"; mychar = 'k';
+ proc(mystr, mychar);
+}
+
+fn proc(mystr : &str, mychar : char) {
+ println!("Input: mystr = {mystr}, mychar = {mychar}");
+ let mut cnt = 0;
+ for l in mystr.chars() {
+ if l == mychar {
+ cnt += 1;
+ }
+ }
+ let i :f32 = 100.0 * cnt as f32 / mystr.len() as f32;
+ println!("Output: {}", i.round());
+}
diff --git a/challenge-273/zapwai/rust/ch-2.rs b/challenge-273/zapwai/rust/ch-2.rs
new file mode 100644
index 0000000000..750d65dd9c
--- /dev/null
+++ b/challenge-273/zapwai/rust/ch-2.rs
@@ -0,0 +1,38 @@
+fn main() {
+ let mut mystr = "aabb";
+ proc(mystr);
+ mystr = "abab";
+ proc(mystr);
+ mystr = "aaa";
+ proc(mystr);
+ mystr = "bbb";
+ proc(mystr);
+}
+
+fn proc(mystr : &str) {
+ println!("Input: mystr = {mystr}");
+ let mut ver : bool = false;
+ for l in mystr.chars() {
+ if l == 'b' {
+ ver = true;
+ }
+ }
+ let mut bflag : bool = false;
+ if ver {
+ for l in mystr.chars() {
+ if l == 'a' && bflag {
+ ver = false;
+ break;
+ } else {
+ if l == 'b' {
+ bflag = true;
+ }
+ }
+ }
+ }
+ if ver {
+ println!("Output: true");
+ } else {
+ println!("Output: false");
+ }
+}