use std::cmp::Ordering;
use sha2::{Digest, Sha256};
const TWITTER_ACCOUNTS: &[&str] = &["userX", "userY", "userZ"];
const SEED: u16 = 666;
fn main() {
let target_account = TWITTER_ACCOUNTS
.iter()
.map(|account| {
let mut hasher = Sha256::new();
hasher.update(account.as_bytes());
let digest = hasher.finalize();
let mut magic_number = (digest[0] as u16) << 8;
magic_number |= digest[1] as u16;
magic_number = magic_number % 999;
let distance = magic_number.abs_diff(SEED);
(*account, distance)
})
.min_by(|x, y| match x.1.cmp(&y.1) {
Ordering::Equal => x.0.cmp(y.0),
res @ _ => res,
})
.map(|(account, _)| account)
.expect("should returns a value");
println!("{target_account}");
}