Wrote program for Day 33

This commit is contained in:
Mariano Riefolo 2024-08-27 12:02:27 +02:00
parent 836fef728d
commit 5eb41602b9
5 changed files with 54 additions and 1 deletions

View File

@ -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: |

View File

@ -0,0 +1,6 @@
[package]
name = "day33"
version = "0.1.0"
edition = "2021"
[dependencies]

View 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
}

View 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);
}

View 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.");
}
}