aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZapwai <zapwai@gmail.com>2024-01-03 13:05:33 -0500
committerGitHub <noreply@github.com>2024-01-03 13:05:33 -0500
commitd9939e7b1ea45317c2d5c83cbc6ac9456a7065fd (patch)
treeb79a4a3dd6438a4a0935048b7303aef6d730ce5f
parentbf5891888bbc7d1f4a2221154c1cce6c983e5c19 (diff)
downloadperlweeklychallenge-club-d9939e7b1ea45317c2d5c83cbc6ac9456a7065fd.tar.gz
perlweeklychallenge-club-d9939e7b1ea45317c2d5c83cbc6ac9456a7065fd.tar.bz2
perlweeklychallenge-club-d9939e7b1ea45317c2d5c83cbc6ac9456a7065fd.zip
Rust for week 250
-rw-r--r--challenge-250/zapwai/rust/ch-1.rs18
-rw-r--r--challenge-250/zapwai/rust/ch-2.rs36
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-250/zapwai/rust/ch-1.rs b/challenge-250/zapwai/rust/ch-1.rs
new file mode 100644
index 0000000000..5aaa43811e
--- /dev/null
+++ b/challenge-250/zapwai/rust/ch-1.rs
@@ -0,0 +1,18 @@
+fn main() {
+ let v = vec![0,1,2];
+ let v2 = vec![4,3,2,1];
+ proc(v);
+ proc(v2);
+}
+
+fn proc(v :Vec<usize>) {
+ println!("Input: ints = {:?}", v);
+ let mut max :i32 = -1;
+ for i in 0 .. v.len() {
+ if i%10==v[i] {
+ max = i as i32;
+ break;
+ }
+ }
+ println!("Output: {max}");
+}
diff --git a/challenge-250/zapwai/rust/ch-2.rs b/challenge-250/zapwai/rust/ch-2.rs
new file mode 100644
index 0000000000..834662da3b
--- /dev/null
+++ b/challenge-250/zapwai/rust/ch-2.rs
@@ -0,0 +1,36 @@
+fn main() {
+ let t = vec!["perl", "2", "000", "python", "r4ku"];
+ let t2 = vec!["001", "1", "000", "0001"];
+ proc(t);
+ proc(t2);
+}
+
+fn proc(t :Vec<&str>) {
+ let mut max :i32 = 0;
+ for i in t.iter() {
+ let c = val(i);
+ if max < c {
+ max = c;
+ }
+ }
+ println!("Input: str = {:?}",t);
+ println!("Output: {max}");
+}
+
+fn val(i :&str) -> i32 {
+ return if is_num(i) {
+ i.parse::<i32>().unwrap()
+ } else {
+ i.len() as i32
+ };
+}
+
+fn is_num (i :&str) -> bool {
+ let mut cnt = 0;
+ for c in i.chars() {
+ if c.is_digit(10) {
+ cnt += 1;
+ }
+ }
+ return if cnt == i.len() {true} else {false};
+}