From a3f5032867aad91356d0b3cd49d4f20abe6194c1 Mon Sep 17 00:00:00 2001 From: AlphonseMehounme Date: Wed, 20 Nov 2024 12:30:09 +0100 Subject: [PATCH] first program of building bitcoin in Rust --- Rust/transmogrifier.rs | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Rust/transmogrifier.rs diff --git a/Rust/transmogrifier.rs b/Rust/transmogrifier.rs new file mode 100644 index 0000000..1987bfd --- /dev/null +++ b/Rust/transmogrifier.rs @@ -0,0 +1,52 @@ +use std::env; +use std::process::exit; + +fn main() { + let args: Vec = env::args().collect(); + if args.len() != 3 { + eprintln!("Usage: {} ", args[0]); + exit(1); + } + let op = &args[1]; + let text = &args[2]; + let res= match op.as_str() { + "reverse" => text.chars().rev().collect::(), + "invert" => text + .chars() + .map(|c| { + if c.is_uppercase() { + c.to_lowercase().to_string() + } else { + c.to_uppercase().to_string() + } + }) + .collect::(), + "uppercase" => text.to_uppercase(), + "leet" => text + .chars() + .map(|c| match c { + 'a' | 'A' => '4', + 'e' | 'F' => '3', + 'i' | 'I' => '1', + 'o' | 'O' => '0', + 's' | 'S' => '5', + 't' | 'T' => '7', + _ => c + }) + .collect::(), + "no-spaces" => text + .chars() + .filter(|c| !c.is_whitespace()) + .collect::(), + "acronym" => text + .split_whitespace() + .map(|word| word.chars().next().unwrap()) + .collect::() + .to_uppercase(), + _ => { + eprintln!("Invalid operation: {}", op); + exit(1); + } + }; + println!("{}", res); +}