Wrote program for Day 56
This commit is contained in:
parent
59b38baace
commit
22bf0a9d51
@ -102,7 +102,7 @@ We encourage you to share your progress and ask questions in the Discussions sec
|
|||||||
| Day #53 | [Javelin Parabolic Throw](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-08/Day-53_Javelin-Parabolic-Throw) | :white_check_mark: |
|
| Day #53 | [Javelin Parabolic Throw](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-08/Day-53_Javelin-Parabolic-Throw) | :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 #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_large_square: |
|
| 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_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 #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: |
|
||||||
|
6
Week-08/Day-56_Convert-To-Hex/day56/Cargo.toml
Normal file
6
Week-08/Day-56_Convert-To-Hex/day56/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "day56"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
11
Week-08/Day-56_Convert-To-Hex/day56/src/lib.rs
Normal file
11
Week-08/Day-56_Convert-To-Hex/day56/src/lib.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
|
pub fn to_hex(text: &str) -> String {
|
||||||
|
text.chars()
|
||||||
|
.fold(String::new(), |mut output, b| {
|
||||||
|
let _ = write!(&mut output, "{:02x} ", b as u8);
|
||||||
|
output
|
||||||
|
})
|
||||||
|
.trim()
|
||||||
|
.to_owned()
|
||||||
|
}
|
12
Week-08/Day-56_Convert-To-Hex/day56/src/main.rs
Normal file
12
Week-08/Day-56_Convert-To-Hex/day56/src/main.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
use day56::to_hex;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
print!("Enter a string: ");
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
|
let mut buffer = String::new();
|
||||||
|
io::stdin().read_line(&mut buffer).unwrap();
|
||||||
|
let text = buffer.trim();
|
||||||
|
println!("Hexadecimal representation: {}", to_hex(text));
|
||||||
|
}
|
27
Week-08/Day-56_Convert-To-Hex/day56/tests/examples.rs
Normal file
27
Week-08/Day-56_Convert-To-Hex/day56/tests/examples.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
toHex("hello world") ➞ "68 65 6c 6c 6f 20 77 6f 72 6c 64"
|
||||||
|
|
||||||
|
toHex("Big Boi") ➞ "42 69 67 20 42 6f 69"
|
||||||
|
|
||||||
|
toHex("Marty Poppinson") ➞ "4d 61 72 74 79 20 50 6f 70 70 69 6e 73 6f 6e"
|
||||||
|
*/
|
||||||
|
#[cfg(test)]
|
||||||
|
mod examples {
|
||||||
|
use day56::to_hex;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_1() {
|
||||||
|
assert_eq!(to_hex("hello world"), "68 65 6c 6c 6f 20 77 6f 72 6c 64");
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_2() {
|
||||||
|
assert_eq!(to_hex("Big Boi"), "42 69 67 20 42 6f 69");
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_3() {
|
||||||
|
assert_eq!(
|
||||||
|
to_hex("Marty Poppinson"),
|
||||||
|
"4d 61 72 74 79 20 50 6f 70 70 69 6e 73 6f 6e"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user