42 lines
924 B
Rust
42 lines
924 B
Rust
use std::{
|
|
io::{self, Write},
|
|
process::exit,
|
|
};
|
|
|
|
use day40::larry_array;
|
|
|
|
fn main() {
|
|
print!("Insert the Larry's array (space separated numbers from 1 to the #numbers): ");
|
|
io::stdout().flush().expect("Failed to flush stdout");
|
|
|
|
let mut buffer = String::new();
|
|
io::stdin()
|
|
.read_line(&mut buffer)
|
|
.expect("Failed to read line");
|
|
|
|
let array = buffer
|
|
.split_whitespace()
|
|
.map(|x| match x.parse() {
|
|
Ok(x) => x,
|
|
Err(e) => {
|
|
eprintln!("{e}");
|
|
exit(1);
|
|
}
|
|
})
|
|
.collect();
|
|
|
|
match larry_array(array) {
|
|
Ok(x) => {
|
|
if x {
|
|
println!("The array can be sorted!");
|
|
} else {
|
|
println!("The array cannot be sorted!");
|
|
}
|
|
}
|
|
Err(e) => {
|
|
eprintln!("{e}");
|
|
exit(1);
|
|
}
|
|
};
|
|
}
|