28 lines
734 B
Rust
28 lines
734 B
Rust
|
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);
|
||
|
}
|