aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-332/benjamin-andre/rust/ch-1.rs16
-rwxr-xr-xchallenge-332/benjamin-andre/rust/ch-2.rs17
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-332/benjamin-andre/rust/ch-1.rs b/challenge-332/benjamin-andre/rust/ch-1.rs
new file mode 100755
index 0000000000..7b96164000
--- /dev/null
+++ b/challenge-332/benjamin-andre/rust/ch-1.rs
@@ -0,0 +1,16 @@
+#!/bin/sh
+//usr/bin/env rustc --test $0 -o kachow && ./kachow --nocapture; rm -f kachow ; exit
+
+fn binary_date(date: &str) -> String {
+ date.split('-')
+ .map(|part| format!("{:b}", part.parse::<u32>().unwrap()))
+ .collect::<Vec<_>>()
+ .join("-")
+}
+
+#[test]
+fn example() {
+ assert_eq!(binary_date("2025-07-26"), "11111101001-111-11010");
+ assert_eq!(binary_date("2000-02-02"), "11111010000-10-10");
+ assert_eq!(binary_date("2024-12-31"), "11111101000-1100-11111");
+}
diff --git a/challenge-332/benjamin-andre/rust/ch-2.rs b/challenge-332/benjamin-andre/rust/ch-2.rs
new file mode 100755
index 0000000000..f847c4af3c
--- /dev/null
+++ b/challenge-332/benjamin-andre/rust/ch-2.rs
@@ -0,0 +1,17 @@
+#!/bin/sh
+//usr/bin/env rustc --test $0 -o kachow && ./kachow --nocapture; rm -f kachow ; exit
+
+fn odd_letters(s: &str) -> bool {
+ let mut counts = std::collections::HashMap::new();
+ for c in s.chars() {
+ *counts.entry(c).or_insert(0) += 1;
+ }
+ counts.values().all(|&count| count % 2 == 1)
+}
+
+#[test]
+fn example() {
+ assert_eq!(odd_letters("weekly"), false);
+ assert_eq!(odd_letters("perl"), true);
+ assert_eq!(odd_letters("challenge"), false);
+}