From d7e5af1ff9d9aa40a71ae3f535ee9a4bccff6b4c Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Fri, 7 Oct 2022 23:18:37 +0000 Subject: [PATCH 1/2] Setting up GitHub Classroom Feedback From c494298866147aee8e09ff1e7775e4b9f442a941 Mon Sep 17 00:00:00 2001 From: h_hue <28158318+hhues@users.noreply.github.com> Date: Fri, 14 Oct 2022 18:17:06 -0400 Subject: [PATCH 2/2] Finished the problem --- src/main.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index bbb5865..8c35698 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,8 @@ fn validate_grading_system() { /// Calculate the grade fn calculate_grade(carrots: i32, nuts: i32, seeds: i32) -> i32 { - todo!() + let final_grade = (carrots + nuts) * (carrots + nuts + seeds); + return final_grade; } /// Validate the safety system @@ -49,7 +50,17 @@ fn calculate_safety_status( has_carrot: bool, friends_nearby: i32, ) -> bool { - todo!() + return if day_time && !wolves_nearby { + true + } else { + if has_carrot { + true + } else if friends_nearby > 3 { + true + } else { + false + } + }; } /// Validate the simulation @@ -67,7 +78,19 @@ fn validate_simulation() { /// Simulate the rabbit population fn simulate(starting_rabbits: i128) -> i32 { - todo!() + let mut rabbits = starting_rabbits; + let mut count = 0; + + while rabbits > 1 { + if rabbits % 2 == 0 { + rabbits = rabbits / 2; + } else { + rabbits = (rabbits * 3) + 1; + } + count += 1; + } + + return count; } #[cfg(test)]