Skip to content

Commit

Permalink
first program of building bitcoin in Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphonseMehounme committed Nov 20, 2024
1 parent ec87716 commit a3f5032
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Rust/transmogrifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::env;
use std::process::exit;

fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 3 {
eprintln!("Usage: {} <op> <text>", args[0]);
exit(1);
}
let op = &args[1];
let text = &args[2];
let res= match op.as_str() {
"reverse" => text.chars().rev().collect::<String>(),
"invert" => text
.chars()
.map(|c| {
if c.is_uppercase() {
c.to_lowercase().to_string()
} else {
c.to_uppercase().to_string()
}
})
.collect::<String>(),
"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::<String>(),
"no-spaces" => text
.chars()
.filter(|c| !c.is_whitespace())
.collect::<String>(),
"acronym" => text
.split_whitespace()
.map(|word| word.chars().next().unwrap())
.collect::<String>()
.to_uppercase(),
_ => {
eprintln!("Invalid operation: {}", op);
exit(1);
}
};
println!("{}", res);
}

0 comments on commit a3f5032

Please sign in to comment.