Wrote program for Day 22
https://github.com/LiveGray/100-Days-Of-Rust/issues/6
This commit is contained in:
parent
9608d466d4
commit
0c44dc91f8
@ -68,7 +68,7 @@ We encourage you to share your progress and ask questions in the Discussions sec
|
||||
| Day #19 | [URL Shortener](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-03/Day-19_URL-Shortener) | :white_check_mark: |
|
||||
| Day #20 | [API Challenge](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-03/Day-20_API-Challenge) | :white_check_mark: |
|
||||
| Day #21 | [Random Maze Generator](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-03/Day-21_Random-Maze-Generator) | :white_check_mark: |
|
||||
| Day #22 | [Marcio Mellos Challenge](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-04/Day-22_Marcio-Mellos-Challenge) | :white_large_square: |
|
||||
| Day #22 | [Marcio Mellos Challenge](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-04/Day-22_Marcio-Mellos-Challenge) | :white_check_mark: |
|
||||
| Day #23 | [The Dining Philosophers](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-04/Day-23_The-Dining_Philosophers) | :white_large_square: |
|
||||
| Day #24 | [The Josephus Problem](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-04/Day-24_The-Josephus-Problem) | :white_large_square: |
|
||||
| Day #25 | [Coin Trouble](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-04/Day-25_Coin-Trouble) | :white_large_square: |
|
||||
|
6
Week-04/Day-22_Marcio-Mellos-Challenge/day22/Cargo.toml
Normal file
6
Week-04/Day-22_Marcio-Mellos-Challenge/day22/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "day22"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
7
Week-04/Day-22_Marcio-Mellos-Challenge/day22/src/lib.rs
Normal file
7
Week-04/Day-22_Marcio-Mellos-Challenge/day22/src/lib.rs
Normal file
@ -0,0 +1,7 @@
|
||||
pub fn area_to_fields(area: f64) -> f64 {
|
||||
let field_area = 105f64 * 68f64;
|
||||
let area_m2 = area * 1000f64 * 1000f64;
|
||||
let result = area_m2 / field_area;
|
||||
let integer_result: usize = (result * 1000f64) as usize;
|
||||
integer_result as f64 / 1000f64
|
||||
}
|
22
Week-04/Day-22_Marcio-Mellos-Challenge/day22/src/main.rs
Normal file
22
Week-04/Day-22_Marcio-Mellos-Challenge/day22/src/main.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use std::io::{self, Write};
|
||||
|
||||
use day22::area_to_fields;
|
||||
|
||||
fn main() {
|
||||
let mut buffer = String::new();
|
||||
|
||||
print!("Insert the deforested area in km2: ");
|
||||
io::stdout().flush().expect("Failed to flush stdout");
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut buffer)
|
||||
.expect("Failed to read line");
|
||||
|
||||
let area = buffer.trim().parse().expect("The area must be an integer");
|
||||
|
||||
let fields = area_to_fields(area);
|
||||
println!(
|
||||
"{} km2 is equivalent to {:.3} football fields",
|
||||
area, fields
|
||||
);
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
#[cfg(test)]
|
||||
mod example {
|
||||
use day22::area_to_fields;
|
||||
|
||||
#[test]
|
||||
fn example() {
|
||||
assert_eq!(area_to_fields(1.034), 144.817);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user