Rust Solution!
Went with the naive algorithm for testing for a prime number. Could always improve on that if needed :shruggy:
My test cases for these are also getting thinner and thinner as we go on...
fn is_prime(num: u64) -> bool { if num == 0 { return false; } for i in 2..num { if num % i == 0 { return false; } } true } pub fn number_property(i: i64) -> (bool, bool, bool) { let is_even = i % 2 == 0; let is_divisible_by_ten = i % 10 == 0; let is_prime = if i > 0 { is_prime(i as u64) } else { false }; (is_prime, is_even, is_divisible_by_ten) } #[cfg(test)] mod tests { use crate::number_property; #[test] fn it_works_for_the_examples() { assert_eq!(number_property(7), (true, false, false)); assert_eq!(number_property(10), (false, true, true)); } #[test] fn it_works_for_negative_examples() { assert_eq!(number_property(-7), (false, false, false)); assert_eq!(number_property(-10), (false, true, true)); } }
Nice!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Rust Solution!
Went with the naive algorithm for testing for a prime number. Could always improve on that if needed :shruggy:
My test cases for these are also getting thinner and thinner as we go on...
Nice!