Wrote program for Day 57
This commit is contained in:
parent
22bf0a9d51
commit
7b89e4760a
@ -103,7 +103,7 @@ We encourage you to share your progress and ask questions in the Discussions sec
|
|||||||
| Day #54 | [RGB To Hex Color Convertor](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-08/Day-54_RGB-To-Hex-Color-Converter) | :white_check_mark: |
|
| Day #54 | [RGB To Hex Color Convertor](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-08/Day-54_RGB-To-Hex-Color-Converter) | :white_check_mark: |
|
||||||
| Day #55 | [Filter Repeating Character Strings](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-08/Day-55_Filter_Repeating-Character-Strings) | :white_check_mark: |
|
| Day #55 | [Filter Repeating Character Strings](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-08/Day-55_Filter_Repeating-Character-Strings) | :white_check_mark: |
|
||||||
| Day #56 | [Convert To Hex](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-08/Day-56_Convert-To-Hex) | :white_check_mark: |
|
| Day #56 | [Convert To Hex](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-08/Day-56_Convert-To-Hex) | :white_check_mark: |
|
||||||
| Day #57 | [Magic Sigil Generator](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-57_Magic-Sigil-Generator) | :white_large_square: |
|
| Day #57 | [Magic Sigil Generator](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-57_Magic-Sigil-Generator) | :white_check_mark: |
|
||||||
| Day #58 | [Create A Dice Roller](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-58_Create-A-Dice-Roller) | :white_large_square: |
|
| Day #58 | [Create A Dice Roller](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-58_Create-A-Dice-Roller) | :white_large_square: |
|
||||||
| Day #59 | [Perfectly Balanced](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-59_Perfectly-Balanced) | :white_large_square: |
|
| Day #59 | [Perfectly Balanced](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-59_Perfectly-Balanced) | :white_large_square: |
|
||||||
| Day #60 | [A Game Of Threes](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-60_A-Game-Of-Thrones) | :white_large_square: |
|
| Day #60 | [A Game Of Threes](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-60_A-Game-Of-Thrones) | :white_large_square: |
|
||||||
|
6
Week-09/Day-57_Magic-Sigil-Generator/day57/Cargo.toml
Normal file
6
Week-09/Day-57_Magic-Sigil-Generator/day57/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "day57"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
20
Week-09/Day-57_Magic-Sigil-Generator/day57/src/lib.rs
Normal file
20
Week-09/Day-57_Magic-Sigil-Generator/day57/src/lib.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
pub fn sigilize(desire: &str) -> String {
|
||||||
|
let vowels = ['A', 'E', 'I', 'O', 'U'];
|
||||||
|
let mut found = HashMap::new();
|
||||||
|
let mut result = String::new();
|
||||||
|
for ch in desire
|
||||||
|
.to_uppercase()
|
||||||
|
.split_whitespace()
|
||||||
|
.collect::<String>()
|
||||||
|
.chars()
|
||||||
|
.rev()
|
||||||
|
{
|
||||||
|
if !vowels.iter().any(|c| *c == ch) && !found.contains_key(&ch) {
|
||||||
|
result.push(ch);
|
||||||
|
found.entry(ch).or_insert(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.chars().rev().collect()
|
||||||
|
}
|
11
Week-09/Day-57_Magic-Sigil-Generator/day57/src/main.rs
Normal file
11
Week-09/Day-57_Magic-Sigil-Generator/day57/src/main.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
use day57::sigilize;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
print!("Enter your desire: ");
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
|
let mut desire = String::new();
|
||||||
|
io::stdin().read_line(&mut desire).unwrap();
|
||||||
|
println!("Sigilized desire: {}", sigilize(desire.trim()));
|
||||||
|
}
|
29
Week-09/Day-57_Magic-Sigil-Generator/day57/tests/examples.rs
Normal file
29
Week-09/Day-57_Magic-Sigil-Generator/day57/tests/examples.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
sigilize("i am healthy") ➞ "MLTHY"
|
||||||
|
|
||||||
|
sigilize("I FOUND MY SOULMATE") ➞ "FNDYSLMT"
|
||||||
|
|
||||||
|
sigilize("I have a job I enjoy and it pays well") ➞ "HVBJNDTPYSWL"
|
||||||
|
*/
|
||||||
|
#[cfg(test)]
|
||||||
|
mod examples {
|
||||||
|
use day57::sigilize;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn example1() {
|
||||||
|
assert_eq!(sigilize("i am healthy"), "MLTHY");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn example2() {
|
||||||
|
assert_eq!(sigilize("I FOUND MY SOULMATE"), "FNDYSLMT");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn example3() {
|
||||||
|
assert_eq!(
|
||||||
|
sigilize("I have a job I enjoy and it pays well"),
|
||||||
|
"HVBJNDTPYSWL"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user