100-days-of-rust/Week-03/Day-17_Prison-Break/day17/src/main.rs

28 lines
734 B
Rust
Raw Normal View History

2024-08-11 10:08:41 +00:00
use day17::freed_prisoners;
use std::io::{self, Write};
fn main() {
let mut buffer = String::new();
print!("Enter the cells (0s and 1s space separated): ");
io::stdout().flush().expect("Failed to flush stdout");
std::io::stdin()
.read_line(&mut buffer)
.expect("Failed to read from stdin");
let cells: Vec<bool> = buffer
.split_whitespace()
.map(
|x| match x.parse::<u8>().expect("Only numbers are expected") {
0 => false,
1 => true,
_ => panic!("Only 0s and 1s are allowed"),
},
)
.collect();
let result = freed_prisoners(&cells);
println!("You can free {} prisoners", result);
}