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)]