Wrote program for Day 33
This commit is contained in:
parent
836fef728d
commit
5eb41602b9
@ -79,7 +79,7 @@ We encourage you to share your progress and ask questions in the Discussions sec
|
|||||||
| Day #30 | [The Maximum Value](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-30_The-Maximum-Value) | :white_check_mark: |
|
| Day #30 | [The Maximum Value](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-30_The-Maximum-Value) | :white_check_mark: |
|
||||||
| Day #31 | [The Time In Words](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-31_The-Time-In-Words) | :white_check_mark: |
|
| Day #31 | [The Time In Words](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-31_The-Time-In-Words) | :white_check_mark: |
|
||||||
| Day #32 | [Climbing The Leaderboard](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-32_Climbing-The-Leaderboard) | :white_check_mark: |
|
| Day #32 | [Climbing The Leaderboard](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-32_Climbing-The-Leaderboard) | :white_check_mark: |
|
||||||
| Day #33 | [WERTYU](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-33_WERTYU) | :white_large_square: |
|
| Day #33 | [WERTYU](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-33_WERTYU) | :white_check_mark: |
|
||||||
| Day #34 | [Primary Arithmetic](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-34_Primary-Arithmetic) | :white_large_square: |
|
| Day #34 | [Primary Arithmetic](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-34_Primary-Arithmetic) | :white_large_square: |
|
||||||
| Day #35 | [Dog And Gopher](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-35_Dog-And-Gopher) | :white_large_square: |
|
| Day #35 | [Dog And Gopher](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-05/Day-35_Dog-And-Gopher) | :white_large_square: |
|
||||||
| Day #36 | [LCD Display](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-06/Day-36_LCD-Display) | :white_large_square: |
|
| Day #36 | [LCD Display](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-06/Day-36_LCD-Display) | :white_large_square: |
|
||||||
|
6
Week-05/Day-33_WERTYU/day33/Cargo.toml
Normal file
6
Week-05/Day-33_WERTYU/day33/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "day33"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
19
Week-05/Day-33_WERTYU/day33/src/lib.rs
Normal file
19
Week-05/Day-33_WERTYU/day33/src/lib.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
pub fn keyboard_mistake_fix(shifted: &str) -> String {
|
||||||
|
let error = "wertyuiop[]\\sdfghjkl;'xcvbnm,./".to_uppercase();
|
||||||
|
let correct = "qwertyuiop[]asdfghjkl;zxcvbnm,.".to_uppercase();
|
||||||
|
|
||||||
|
assert_eq!(error.len(), correct.len());
|
||||||
|
|
||||||
|
let shifted = shifted.to_uppercase();
|
||||||
|
|
||||||
|
let mut fixed = String::new();
|
||||||
|
for c in shifted.chars() {
|
||||||
|
if let Some(i) = error.find(c) {
|
||||||
|
fixed.push(correct.chars().nth(i).unwrap());
|
||||||
|
} else {
|
||||||
|
fixed.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixed
|
||||||
|
}
|
19
Week-05/Day-33_WERTYU/day33/src/main.rs
Normal file
19
Week-05/Day-33_WERTYU/day33/src/main.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
use day33::keyboard_mistake_fix;
|
||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Insert the text you wrote with your hands on the keyboard one row to the right of the correct position.");
|
||||||
|
print!("> ");
|
||||||
|
io::stdout().flush().expect("Failed to flush");
|
||||||
|
|
||||||
|
let mut buffer = String::new();
|
||||||
|
|
||||||
|
io::stdin()
|
||||||
|
.read_line(&mut buffer)
|
||||||
|
.expect("Failed to read line");
|
||||||
|
|
||||||
|
let shifted = buffer.trim();
|
||||||
|
|
||||||
|
let fixed = keyboard_mistake_fix(shifted);
|
||||||
|
println!("The text you should have typed: {}", fixed);
|
||||||
|
}
|
9
Week-05/Day-33_WERTYU/day33/tests/example.rs
Normal file
9
Week-05/Day-33_WERTYU/day33/tests/example.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#[cfg(test)]
|
||||||
|
mod example {
|
||||||
|
use day33::keyboard_mistake_fix;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_example() {
|
||||||
|
assert_eq!(keyboard_mistake_fix("O S, GOMR YPFSU/"), "I AM FINE TODAY.");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user