From 0cb757c9e4c1e9e78615617a27cac20e91b01d20 Mon Sep 17 00:00:00 2001 From: Manuel Riquelme Date: Tue, 13 Jun 2023 16:27:12 +0200 Subject: [PATCH] reto01 --- ejercicios/reto01/Cargo.toml | 8 +++++ ejercicios/reto01/src/main.rs | 58 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 ejercicios/reto01/Cargo.toml create mode 100644 ejercicios/reto01/src/main.rs diff --git a/ejercicios/reto01/Cargo.toml b/ejercicios/reto01/Cargo.toml new file mode 100644 index 0000000..85c4697 --- /dev/null +++ b/ejercicios/reto01/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "reto01" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/ejercicios/reto01/src/main.rs b/ejercicios/reto01/src/main.rs new file mode 100644 index 0000000..c676087 --- /dev/null +++ b/ejercicios/reto01/src/main.rs @@ -0,0 +1,58 @@ +/* + * 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(); + } + } + } + println!("{}", textfinal) +}