From 0168cc4422b1568788896c9c0bb2c4fbdf7b4f50 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Fri, 7 Oct 2022 02:48:30 +0000 Subject: [PATCH 1/3] Setting up GitHub Classroom Feedback From 362ba4a0bc5d1eae0dbcac1be9255c89ea072182 Mon Sep 17 00:00:00 2001 From: TheUncleLake <100882470+TheUncleLake@users.noreply.github.com> Date: Mon, 28 Nov 2022 14:13:56 -0500 Subject: [PATCH 2/3] Done made 3 tests pass (not sure if the test for safety system is good enough though) --- src/main.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index bbb5865..5d56995 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ fn validate_grading_system() { /// Calculate the grade fn calculate_grade(carrots: i32, nuts: i32, seeds: i32) -> i32 { - todo!() + (carrots + nuts) * (carrots + nuts + seeds) } /// Validate the safety system @@ -49,7 +49,7 @@ fn calculate_safety_status( has_carrot: bool, friends_nearby: i32, ) -> bool { - todo!() + !wolves_nearby && day_time || has_carrot || friends_nearby > 3 } /// Validate the simulation @@ -67,7 +67,17 @@ fn validate_simulation() { /// Simulate the rabbit population fn simulate(starting_rabbits: i128) -> i32 { - todo!() + let mut days: i32 = 0; + let mut rabbits: i128 = starting_rabbits; + while (rabbits > 1) { + if (rabbits % 2 == 0) { + rabbits = rabbits / 2; + } else { + rabbits = rabbits * 3 + 1; + } + days += 1; + } + days } #[cfg(test)] From bd2e21ff4a3689d72dcfc437d98a96dff6f8df8b Mon Sep 17 00:00:00 2001 From: TheUncleLake <100882470+TheUncleLake@users.noreply.github.com> Date: Mon, 28 Nov 2022 14:22:17 -0500 Subject: [PATCH 3/3] minor change Removed unused parentheses --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5d56995..fefd7ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,8 +69,8 @@ fn validate_simulation() { fn simulate(starting_rabbits: i128) -> i32 { let mut days: i32 = 0; let mut rabbits: i128 = starting_rabbits; - while (rabbits > 1) { - if (rabbits % 2 == 0) { + while rabbits > 1 { + if rabbits % 2 == 0 { rabbits = rabbits / 2; } else { rabbits = rabbits * 3 + 1;