Created
October 10, 2020 18:00
-
-
Save coyotte508/f6ab07e32fe7bc558d72171e5235ef83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{stdin, stdout, Write}; | |
fn main() { | |
let stdin = stdin(); | |
let mut stdout = stdout(); | |
let to_guess = String::from("BENEDICT"); | |
let mut letters: u128 = 0; | |
loop { | |
let a = to_guess.chars().map(|x| if x <= 127 as char && letters & (1 << x as u8) > 0 {x} else {'_'}).collect::<String>(); | |
let a = a.chars().map(|x| x.to_string() + &' '.to_string()).collect::<Vec<String>>().join(" "); | |
let a = a.trim_end(); | |
println!("Current word: {}", a); | |
if !a.contains('_') { | |
println!("Congratulations!"); | |
break; | |
} | |
print!("Enter new letter: "); | |
stdout.flush().unwrap(); | |
let mut letter = String::new(); | |
stdin.read_line(& mut letter).expect("Invalid letter"); | |
if letter.trim().len() != 1 { | |
println!("Use only one letter"); | |
continue; | |
} | |
let letter = letter.to_uppercase().chars().next().unwrap(); | |
letters = letters | (1 << letter as u8) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment