This repository has been archived on 2023-10-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
curso_rust_tinchicus/ejercicios/reto01/src/main.rs

61 lines
1.7 KiB
Rust

/*
* Escribe un programa que reciba un texto y transforme lenguaje natural a
* "lenguaje hacker" (conocido realmente como "leet" o "1337"). Este lenguaje
* se caracteriza por sustituir caracteres alfanuméricos.
* - Utiliza esta tabla (https://www.gamehouse.com/blog/leet-speak-cheat-sheet/)
* con el alfabeto y los números en "leet".
* (Usa la primera opción de cada transformación. Por ejemplo "4" para la "a")
*/
fn main() {
let alphabet = String::from_utf8((b'A'..=b'Z').chain(b'0'..=b'9').collect()).unwrap();
println!("{}", alphabet);
let respuesta = [
"4",
"l3",
"[",
")",
"3",
"|=",
"&",
"#",
"1",
",_|",
">|",
"1",
"^^",
"^",
"0",
"|*",
"(_,)",
"l2",
"hu",
"gg",
"pesadooooooooo",
"0",
"yy",
"2",
"3",
"4",
];
let vecalphabet: Vec<_> = alphabet.split("").collect();
let texto = String::from("wtf hijo de puta hay que decirlo mas").to_uppercase();
let vectexto: Vec<_> = texto.split("").collect();
let mut textfinal = "".to_string();
for item in vectexto {
if alphabet.contains(item) {
let index = vecalphabet
.iter()
.position(|&r| r == item.to_string())
.unwrap();
if index != 0 {
//println!("es->{}", respuesta[index]);
textfinal += &respuesta[index].to_string();
}
} else if item == " ".to_string() {
textfinal += &" ".to_string()
}
}
println!("{}", textfinal)
}