100-days-of-rust/Week-03/Day-16_Nim-Game/day16/src/main.rs

26 lines
553 B
Rust

use std::io::{self, Write};
use day16::nim_winner;
fn main() {
let mut buffer = String::new();
print!("How many stones will you have during your turn? ");
io::stdout().flush().expect("Failed to flush stdout.");
io::stdin()
.read_line(&mut buffer)
.expect("Failed to read from stdin");
let stones = buffer
.trim()
.parse()
.expect("Your input is not a valid number");
if nim_winner(stones) {
println!("You will win!");
} else {
println!("You will lose!");
}
}