Wrote program for Day 62
This commit is contained in:
parent
6b024d00bd
commit
09dccbbc8a
@ -108,7 +108,7 @@ We encourage you to share your progress and ask questions in the Discussions sec
|
|||||||
| Day #59 | [Perfectly Balanced](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-59_Perfectly-Balanced) | :white_check_mark: |
|
| Day #59 | [Perfectly Balanced](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-59_Perfectly-Balanced) | :white_check_mark: |
|
||||||
| 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_check_mark: |
|
| 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_check_mark: |
|
||||||
| Day #61 | [Write A Web Crawler](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-61_Write-A-Web-Crawler) | :white_check_mark: |
|
| Day #61 | [Write A Web Crawler](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-61_Write-A-Web-Crawler) | :white_check_mark: |
|
||||||
| Day #62 | [Funny Plant](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-62_Funny-Plant) | :white_large_square: |
|
| Day #62 | [Funny Plant](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-62_Funny-Plant) | :white_check_mark: |
|
||||||
| Day #63 | [The Rabbit Problem](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-63_The-Rabbit-Problem) | :white_large_square: |
|
| Day #63 | [The Rabbit Problem](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-09/Day-63_The-Rabbit-Problem) | :white_large_square: |
|
||||||
| Day #64 | [First Recurring Character](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-10/Day-64_First-Recurring-Character) | :white_large_square: |
|
| Day #64 | [First Recurring Character](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-10/Day-64_First-Recurring-Character) | :white_large_square: |
|
||||||
| Day #65 | [ISBN Validator](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-10/Day-65_ISBN-Validator) | :white_large_square: |
|
| Day #65 | [ISBN Validator](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-10/Day-65_ISBN-Validator) | :white_large_square: |
|
||||||
|
6
Week-09/Day-62_Funny-Plant/day62/Cargo.toml
Normal file
6
Week-09/Day-62_Funny-Plant/day62/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "day62"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
11
Week-09/Day-62_Funny-Plant/day62/src/lib.rs
Normal file
11
Week-09/Day-62_Funny-Plant/day62/src/lib.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
pub fn funny_plant(people: usize, fruits: usize) -> usize {
|
||||||
|
let mut weeks = 1;
|
||||||
|
let mut increment = 0;
|
||||||
|
let mut plants = fruits;
|
||||||
|
while increment < people {
|
||||||
|
increment += plants;
|
||||||
|
plants += increment;
|
||||||
|
weeks += 1;
|
||||||
|
}
|
||||||
|
weeks
|
||||||
|
}
|
35
Week-09/Day-62_Funny-Plant/day62/src/main.rs
Normal file
35
Week-09/Day-62_Funny-Plant/day62/src/main.rs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
use std::{
|
||||||
|
io::{self, Write},
|
||||||
|
process::exit,
|
||||||
|
};
|
||||||
|
|
||||||
|
use day62::funny_plant;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut buffer = String::new();
|
||||||
|
print!("Enter the number of people to fed: ");
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
|
io::stdin().read_line(&mut buffer).unwrap();
|
||||||
|
let people = match buffer.trim().parse() {
|
||||||
|
Ok(x) => x,
|
||||||
|
Err(_) => {
|
||||||
|
eprintln!("Not a valid number");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
buffer.clear();
|
||||||
|
print!("Enter the number of fruits: ");
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
|
io::stdin().read_line(&mut buffer).unwrap();
|
||||||
|
let fruits = match buffer.trim().parse() {
|
||||||
|
Ok(x) => x,
|
||||||
|
Err(_) => {
|
||||||
|
eprintln!("Not a valid number");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let weeks = funny_plant(people, fruits);
|
||||||
|
println!("The minimum number of weeks is {weeks}");
|
||||||
|
}
|
19
Week-09/Day-62_Funny-Plant/day62/tests/examples.rs
Normal file
19
Week-09/Day-62_Funny-Plant/day62/tests/examples.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#[cfg(test)]
|
||||||
|
mod examples {
|
||||||
|
use day62::funny_plant;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn example1() {
|
||||||
|
assert_eq!(funny_plant(200, 15), 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn example2() {
|
||||||
|
assert_eq!(funny_plant(50000, 1), 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn example3() {
|
||||||
|
assert_eq!(funny_plant(150000, 250), 9);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user