Wrote program for Day 3

This commit is contained in:
Mariano Riefolo 2024-07-28 13:57:52 +02:00
parent 042f3bf7fa
commit 0dc867ecb5
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,6 @@
[package]
name = "barbecue_skewers"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -0,0 +1,57 @@
fn bbq_skewers(skewers: &'static [&str]) -> (usize, usize) {
let mut vegetarian = 0;
for skewer in skewers {
if ! skewer.contains('x') {
vegetarian += 1;
}
}
return (vegetarian, skewers.len() - vegetarian);
}
#[test]
fn test1() {
assert_eq!(
bbq_skewers(&[
"--xo--x--ox--",
"--xx--x--xx--",
"--oo--o--oo--",
"--xx--x--ox--",
"--xx--x--ox--"
]),
(1, 4)
);
}
#[test]
fn test2() {
assert_eq!(
bbq_skewers(&[
"--oooo-ooo---",
"--xx--x--xx--",
"--o---o--oo--",
"--xx--x--ox--",
"--xx--x--ox--"
]),
(2, 3)
);
}
#[test]
fn test3() {
assert_eq!(
bbq_skewers(&[
"--oooo-ooo--",
"--xxxxxxxx--",
"--o---",
"-o-----o---x--",
"--o---o-----"
]),
(3, 2)
);
}
fn main() {
println!("Run `cargo test`.");
}