diff --git "a/Retos/Reto #28 - EXPRESI\303\223N MATEM\303\201TICA [Media]/rust/sugus-labs.rs" "b/Retos/Reto #28 - EXPRESI\303\223N MATEM\303\201TICA [Media]/rust/sugus-labs.rs" new file mode 100644 index 0000000000..76aaa35829 --- /dev/null +++ "b/Retos/Reto #28 - EXPRESI\303\223N MATEM\303\201TICA [Media]/rust/sugus-labs.rs" @@ -0,0 +1,45 @@ +use evalexpr::*; +use std::any::type_name; +use std::panic; + +fn type_of(_: T) -> &'static str { + type_name::() +} + +fn test_math_expr(mut text: String, symbol_vec: Vec) -> bool { + + let mut is_math_expr: bool = false; + let mut text_symbol_vec: Vec = vec![]; + + let _eval: Result = eval(&text); + //println!(" - {:?}", _eval); + + let response: Value = match _eval { + Ok(res) => res, + Err(err) => return false + }; + + for c in text.replace(" ", "").chars() { + //println!("{}", c); + if !symbol_vec.contains(&c) + && !c.is_digit(10) { + //println!(" - {}", c); + is_math_expr = false; + return is_math_expr + } + } + + return true +} + +fn main() { + + let mut symbol_vec: Vec = vec![' ', '.']; + let mut operation_vec: Vec = vec![ + '+', '-', '*', '/', '%']; + symbol_vec.append(&mut operation_vec); + let text: String = String::from("1 + 1 / -6.5"); + let is_math_expr: bool = test_math_expr(text, symbol_vec); + println!("{}", is_math_expr) + +} \ No newline at end of file diff --git "a/Retos/Reto #29 - EL CAR\303\201CTER INFILTRADO [F\303\241cil]/python/sugus-labs.py" "b/Retos/Reto #29 - EL CAR\303\201CTER INFILTRADO [F\303\241cil]/python/sugus-labs.py" new file mode 100644 index 0000000000..63b12077c9 --- /dev/null +++ "b/Retos/Reto #29 - EL CAR\303\201CTER INFILTRADO [F\303\241cil]/python/sugus-labs.py" @@ -0,0 +1,23 @@ +def diff_chars(first_text: str, second_text: str): + + if not isinstance(first_text, str) or not isinstance(second_text, str): + raise ValueError("We need only strings!") + + if len(first_text) != len(second_text): + raise ValueError("The two text needs to have the same length!") + + error_list = [] + + for c1, c2 in zip(first_text, second_text): + if c1 != c2: + error_list.append((c1, c2)) + #print(c1, c2) + + return error_list + +if __name__ == "__main__": + + first_text = "Me llamo.Brais Moure" + second_text = "Me llamo brais moure" + result_list = diff_chars(first_text, second_text) + print(result_list) \ No newline at end of file diff --git "a/Retos/Reto #29 - EL CAR\303\201CTER INFILTRADO [F\303\241cil]/rust/sugus-labs.rs" "b/Retos/Reto #29 - EL CAR\303\201CTER INFILTRADO [F\303\241cil]/rust/sugus-labs.rs" new file mode 100644 index 0000000000..7acb72db64 --- /dev/null +++ "b/Retos/Reto #29 - EL CAR\303\201CTER INFILTRADO [F\303\241cil]/rust/sugus-labs.rs" @@ -0,0 +1,26 @@ +fn diff_chars(first_text: String, sec_text: String) -> Vec<(char, char)> { + + let mut error_vec: Vec<(char, char)> = vec![]; + let first_text_vec: Vec = first_text.chars().collect(); + let sec_text_vec: Vec = sec_text.chars().collect(); + + let iter = first_text_vec.iter().zip(sec_text_vec.iter()); + + for (c1, c2) in iter { + //println!("{} {}", c1, c2); + if c1 != c2 { + error_vec.push((*c1, *c2)) + } + } + + return error_vec; +} + +fn main() { + + let first_text: String = String::from("Me llamo.Brais Moure"); + let sec_text: String = String::from("Me llamo brais moure"); + let result_vec: Vec<(char, char)> = diff_chars(first_text, sec_text); + println!("{:?}", result_vec); + +} \ No newline at end of file diff --git a/Retos/Reto #30 - EL TECLADO T9 [Media]/python/sugus-labs.py b/Retos/Reto #30 - EL TECLADO T9 [Media]/python/sugus-labs.py new file mode 100644 index 0000000000..b8edfe4fa8 --- /dev/null +++ b/Retos/Reto #30 - EL TECLADO T9 [Media]/python/sugus-labs.py @@ -0,0 +1,56 @@ +from bs4 import BeautifulSoup +import requests +import re +import string + +def download_t9_alphabet(): + url = "https://es.wikipedia.org/wiki/Texto_predictivo" + body = requests.get(url) + body_text = body.content + + clean = re.compile('<.*?>') + + alphabet_dict = dict() + + soup = BeautifulSoup(body_text, 'lxml') + divs = soup.find_all("div", class_="mw-parser-output") + for div in divs: + uls = div.find_all("ul") + for ul in uls: + lis = ul.find_all("li") + for li in lis: + try: + clean_line = re.sub(clean, '', str(li)) + number_char = str(clean_line[0]) + corr_chars = clean_line.split("(")[1].split(")")[0] + corr_char_list = list(corr_chars) + alphabet_dict[number_char] = corr_char_list + #print(clean_line, number_char, corr_chars) + except: + break + if number_char == "9": + break + if number_char == "9": + break + + return alphabet_dict + +def t9_to_text(text: str, alphabet_dict: dict = download_t9_alphabet): + + """ text with numbers to words function """ + + new_str_list = [] + text_list = text.split("-") + + for t in text_list: + pos = len(t) - 1 + new_char = alphabet_dict.get(t[0])[pos] + new_str_list.append(new_char) + new_str = "".join(new_str_list) + + return new_str + +if __name__ == "__main__": + alphabet_dict = download_t9_alphabet() + new_str = t9_to_text("6-666-88-777-33-3-33-888", alphabet_dict) + print(new_str) \ No newline at end of file diff --git a/Retos/Reto #30 - EL TECLADO T9 [Media]/rust/sugus-labs.rs b/Retos/Reto #30 - EL TECLADO T9 [Media]/rust/sugus-labs.rs new file mode 100644 index 0000000000..f028245b4a --- /dev/null +++ b/Retos/Reto #30 - EL TECLADO T9 [Media]/rust/sugus-labs.rs @@ -0,0 +1,44 @@ +use std::collections::HashMap; + +fn t9_to_text(text: String, alphabet_hash: &HashMap>) { + + let mut new_str_vec: Vec = vec![]; + let text_parts = text.split("-"); + let text_vec = text_parts.collect::>(); + let mut pos: usize; + let mut new_char: char; + let mut ch: char; + + for t in text_vec { + pos = t.len() - 1; + ch = String::from(t).chars().next().unwrap(); + new_char = alphabet_hash.get(&ch); + dbg!(t, pos, new_char); + } + // + // new_char = alphabet_dict.get(t[0])[pos] + // new_str_list.append(new_char) + //new_str = "".join(new_str_list) + + //return new_str +} + +fn main() { + + let text: String = String::from("6-666-88-777-33-3-33-888"); + let alphabet_hash: HashMap> = [ + ('2', vec!['a', 'b', 'c']), + ('3', vec!['d', 'e', 'f']), + ('4', vec!['g', 'h', 'i']), + ('5', vec!['j', 'k', 'l']), + ('6', vec!['m', 'n', 'o']), + ('7', vec!['p', 'q', 'r', 's']), + ('8', vec!['t', 'u', 'v']), + ('9', vec!['w', 'x', 'y', 'z'])] + .iter() + .cloned() + .collect(); + t9_to_text(text, &alphabet_hash); + //println!("{:?}", alphabet_hash); + +} \ No newline at end of file diff --git "a/Retos/Reto #31 - EL \303\201BACO [F\303\241cil]/python/sugus-labs.py" "b/Retos/Reto #31 - EL \303\201BACO [F\303\241cil]/python/sugus-labs.py" new file mode 100644 index 0000000000..11a5df61c1 --- /dev/null +++ "b/Retos/Reto #31 - EL \303\201BACO [F\303\241cil]/python/sugus-labs.py" @@ -0,0 +1,22 @@ +def read_abacus_str(abacus_list: list): + + abacus_number = "" + for line in abacus_list: + num = str(len(line.split("-")[0])) + abacus_number = abacus_number + num + abacus_number = int(abacus_number) + + return abacus_number + +if __name__ == "__main__": + + abacus_list = [ + "O---OOOOOOOO", + "OOO---OOOOOO", + "---OOOOOOOOO", + "OO---OOOOOOO", + "OOOOOOO---OO", + "OOOOOOOOO---", + "---OOOOOOOOO"] + abacus_number = read_abacus_str(abacus_list) + print(abacus_number) \ No newline at end of file diff --git "a/Retos/Reto #31 - EL \303\201BACO [F\303\241cil]/rust/sugus-labs.rs" "b/Retos/Reto #31 - EL \303\201BACO [F\303\241cil]/rust/sugus-labs.rs" new file mode 100644 index 0000000000..36fd99d48d --- /dev/null +++ "b/Retos/Reto #31 - EL \303\201BACO [F\303\241cil]/rust/sugus-labs.rs" @@ -0,0 +1,33 @@ +fn read_abacus_str(abacus_vec: Vec) -> usize { + + let mut abacus_num_str = String::new(); + let mut chunks: Vec<&str> = vec![]; + let mut num; + let abacus_number: usize; + + for line in abacus_vec { + chunks = line.split("---").collect(); + num = chunks[0].len(); + //println!("{:?}", num); + abacus_num_str.push_str(&num.to_string()); + } + let abacus_number: usize = abacus_num_str.parse().unwrap(); + + return abacus_number; + +} + +fn main() { + + let abacus_vec: Vec = vec![ + String::from("O---OOOOOOOO"), + String::from("OOO---OOOOOO"), + String::from("---OOOOOOOOO"), + String::from("OO---OOOOOOO"), + String::from("OOOOOOO---OO"), + String::from("OOOOOOOOO---"), + String::from("---OOOOOOOOO")]; + let abacus_number = read_abacus_str(abacus_vec); + println!("{}",abacus_number); + +} \ No newline at end of file