From 7194a5d29e95b353d44ee1db0bcee8001b880a9e Mon Sep 17 00:00:00 2001 From: Kishan Takoordyal Date: Sun, 17 May 2026 22:45:35 +0400 Subject: [PATCH] Complete exercise: idomatic --- exercise/idiomatic/src/main.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/exercise/idiomatic/src/main.rs b/exercise/idiomatic/src/main.rs index f351f08..1da2538 100644 --- a/exercise/idiomatic/src/main.rs +++ b/exercise/idiomatic/src/main.rs @@ -8,16 +8,28 @@ // Challenge: Clippy doesn't find *everything*. What else would you change to make this code better? -const pi:f32=3.14159265358979323846; -fn count_to_5()->i32{let mut foo =0;loop{if foo>pi as i32{if foo > 5{break;}}foo=foo+1;}return 5;} -fn main() { -println!("I can count to {}", count_to_5()); +use std::f32::consts::PI; + +fn count_to_5() -> i32 { + let mut count = 0; + loop { + if count > PI as i32 && count >= 5 { + break; + } + count += 1; + } + count } +fn main() { + println!("I can count to {}", count_to_5()); +} + #[cfg(test)] mod test { -use super::*; -#[test] -fn test_counting() { -assert_eq!(count_to_5() == 5, true); -} + use super::*; + + #[test] + fn test_counting() { + assert_eq!(count_to_5() == 5, true); + } }