diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-01-15 21:46:29 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-15 21:46:29 +0000 |
| commit | 590ef398889618c72925983871357130f096e919 (patch) | |
| tree | a612a2febd162699425a9efd78640777447464b2 | |
| parent | 809b5857766d121a2a41088d4eacbaa1e0eebb86 (diff) | |
| parent | 311290132e0bb4bd3ccfe4db5909e951bb0c2edb (diff) | |
| download | perlweeklychallenge-club-590ef398889618c72925983871357130f096e919.tar.gz perlweeklychallenge-club-590ef398889618c72925983871357130f096e919.tar.bz2 perlweeklychallenge-club-590ef398889618c72925983871357130f096e919.zip | |
Merge pull request #7413 from zapwai/branch-for-199
Rust code for week 199
| -rw-r--r-- | challenge-199/zapwai/rust/ch-1.rs | 18 | ||||
| -rw-r--r-- | challenge-199/zapwai/rust/ch-2.rs | 21 |
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-199/zapwai/rust/ch-1.rs b/challenge-199/zapwai/rust/ch-1.rs new file mode 100644 index 0000000000..66ca6b7aa0 --- /dev/null +++ b/challenge-199/zapwai/rust/ch-1.rs @@ -0,0 +1,18 @@ +fn main() { + let list = vec![1,2,3,1,1,3]; + // let list = vec![1,2,3]; + // let list = vec![1,1,1,1]; + println!("Input: list = {:?}",list); + let mut cnt = 0; + let mut output = String::from(""); + for i in 0 ..= list.len()-2 { + for j in i+1 ..= list.len()-1 { + if list[i] == list[j] { + cnt += 1; + output += &format!("({},{}) ",i,j); + } + } + } + println!("Output: {cnt}"); + println!("{output}"); +} diff --git a/challenge-199/zapwai/rust/ch-2.rs b/challenge-199/zapwai/rust/ch-2.rs new file mode 100644 index 0000000000..2a394ad4c5 --- /dev/null +++ b/challenge-199/zapwai/rust/ch-2.rs @@ -0,0 +1,21 @@ +fn main() { + let array : Vec<i32> = vec![3,0,1,1,9,7]; + let (x,y,z) : (i32, i32, i32) = (7,2,3); + println!("Input: array = {:?}",array); + let mut cnt = 0; + let mut output = String::from("Good triplets are... \n"); + for i in 0 .. array.len() - 2 { + for j in i + 1 .. array.len() - 1 { + for k in j + 1 .. array.len() { + if ((array[i] - array[j]).abs() <= x) && + ((array[j] - array[k]).abs() <= y) && + ((array[i] - array[k]).abs() <= z) { + cnt += 1; + output += &format!("({},{},{}) -> (i,j,k) = ({},{},{})\n",array[i],array[j],array[k],i,j,k); + } + } + } + } + println!("Output: {cnt}"); + println!("{output}"); +} |
