42 lines
1009 B
Rust
42 lines
1009 B
Rust
|
use std::io::{self, Write};
|
||
|
|
||
|
use day13::can_fit;
|
||
|
|
||
|
fn main() {
|
||
|
let mut buffer = String::new();
|
||
|
|
||
|
print!("Insert the weights separated by spaces: ");
|
||
|
io::stdout().flush().expect("Failed to flush stdout.");
|
||
|
|
||
|
io::stdin()
|
||
|
.read_line(&mut buffer)
|
||
|
.expect("Failed to read from stdin.");
|
||
|
|
||
|
let weights: Vec<usize> = buffer
|
||
|
.trim()
|
||
|
.split(' ')
|
||
|
.filter(|x| !x.is_empty())
|
||
|
.map(|x| {
|
||
|
x.parse()
|
||
|
.expect("Only whole numbers and spaces are allowed.")
|
||
|
})
|
||
|
.collect();
|
||
|
|
||
|
buffer = String::new();
|
||
|
|
||
|
print!("Insert how many bags are available: ");
|
||
|
io::stdout().flush().expect("Failed to flush stdout.");
|
||
|
|
||
|
io::stdin()
|
||
|
.read_line(&mut buffer)
|
||
|
.expect("Failed to read from stdin.");
|
||
|
|
||
|
let bags = buffer.trim().parse().expect("Integer expected.");
|
||
|
|
||
|
if can_fit(&weights, bags) {
|
||
|
println!("There are enough bags.");
|
||
|
} else {
|
||
|
println!("more bags are needed.");
|
||
|
}
|
||
|
}
|