aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-13 23:51:30 +0100
committerGitHub <noreply@github.com>2025-09-13 23:51:30 +0100
commitcb14b22c1a82cdb4f2f32b3fb3d836cf2bb4993a (patch)
tree9b06538a4989d2dd50ca5b2f0f7be11d273a6ad5
parent8390b61d50866417d0f25aeb2a3b43ee2adc5971 (diff)
parent7dd8df88e3133de32beae4a7f5768912de43bc23 (diff)
downloadperlweeklychallenge-club-cb14b22c1a82cdb4f2f32b3fb3d836cf2bb4993a.tar.gz
perlweeklychallenge-club-cb14b22c1a82cdb4f2f32b3fb3d836cf2bb4993a.tar.bz2
perlweeklychallenge-club-cb14b22c1a82cdb4f2f32b3fb3d836cf2bb4993a.zip
Merge pull request #12667 from fer2o3/kachow
feat(338): completed both challenges
-rwxr-xr-xchallenge-338/benjamin-andre/rust/ch-1.rs21
-rwxr-xr-xchallenge-338/benjamin-andre/rust/ch-2.rs19
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-338/benjamin-andre/rust/ch-1.rs b/challenge-338/benjamin-andre/rust/ch-1.rs
new file mode 100755
index 0000000000..798b631543
--- /dev/null
+++ b/challenge-338/benjamin-andre/rust/ch-1.rs
@@ -0,0 +1,21 @@
+#!/bin/sh
+//usr/bin/env rustc --test $0 -o kachow && ./kachow --nocapture; rm -f kachow ; exit
+
+fn highest_row(matrix: &[&[i32]]) -> i32 {
+ matrix.iter().map(|row| row.iter().sum()).max().unwrap()
+}
+
+#[test]
+fn example() {
+ assert_eq!(
+ highest_row(&[&[4, 4, 4, 4], &[10, 0, 0, 0], &[2, 2, 2, 9]]),
+ 16
+ );
+ assert_eq!(highest_row(&[&[1, 5], &[7, 3], &[3, 5]]), 10);
+ assert_eq!(highest_row(&[&[1, 2, 3], &[3, 2, 1]]), 6);
+ assert_eq!(highest_row(&[&[2, 8, 7], &[7, 1, 3], &[1, 9, 5]]), 17);
+ assert_eq!(
+ highest_row(&[&[10, 20, 30], &[5, 5, 5], &[0, 100, 0], &[25, 25, 25]]),
+ 100
+ );
+}
diff --git a/challenge-338/benjamin-andre/rust/ch-2.rs b/challenge-338/benjamin-andre/rust/ch-2.rs
new file mode 100755
index 0000000000..1b3c177d76
--- /dev/null
+++ b/challenge-338/benjamin-andre/rust/ch-2.rs
@@ -0,0 +1,19 @@
+#!/bin/sh
+//usr/bin/env rustc --test $0 -o kachow && ./kachow --nocapture; rm -f kachow ; exit
+
+fn max_distance(arr1: &[i32], arr2: &[i32]) -> i32 {
+ let min1 = *arr1.iter().min().unwrap();
+ let max1 = *arr1.iter().max().unwrap();
+ let min2 = *arr2.iter().min().unwrap();
+ let max2 = *arr2.iter().max().unwrap();
+ std::cmp::max((max1 - min2).abs(), (max2 - min1).abs())
+}
+
+#[test]
+fn example() {
+ assert_eq!(max_distance(&[4, 5, 7], &[9, 1, 3, 4]), 6);
+ assert_eq!(max_distance(&[2, 3, 5, 4], &[3, 2, 5, 5, 8, 7]), 6);
+ assert_eq!(max_distance(&[2, 1, 11, 3], &[2, 5, 10, 2]), 9);
+ assert_eq!(max_distance(&[1, 2, 3], &[3, 2, 1]), 2);
+ assert_eq!(max_distance(&[1, 0, 2, 3], &[5, 0]), 5);
+}