Wrote program for Day 3
This commit is contained in:
parent
042f3bf7fa
commit
0dc867ecb5
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "barbecue_skewers"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
57
Week-01/Day-03_Barbecue-Skewers/barbecue_skewers/src/main.rs
Normal file
57
Week-01/Day-03_Barbecue-Skewers/barbecue_skewers/src/main.rs
Normal 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`.");
|
||||
}
|
Loading…
Reference in New Issue
Block a user