diff --git a/Rust/rustifinity/challenges/countdown.rs b/Rust/rustifinity/challenges/countdown.rs new file mode 100644 index 0000000..c144711 --- /dev/null +++ b/Rust/rustifinity/challenges/countdown.rs @@ -0,0 +1,15 @@ +pub fn countdown(n: u32) -> Vec { + // TODO: Implement the countdown using a while loop +if n == 0 { + vec![0] + } else { + let mut vect : Vec = Vec::new(); + let mut m = n; + while m > 0 { + vect.push(m); + m -= 1; + } + vect.push(0); + vect + } +} diff --git a/Rust/rustifinity/challenges/if-else.rs b/Rust/rustifinity/challenges/if-else.rs new file mode 100644 index 0000000..7e71674 --- /dev/null +++ b/Rust/rustifinity/challenges/if-else.rs @@ -0,0 +1,8 @@ +pub fn is_even(n: i32) -> bool { + // Your code here... + if n % 2 == 0 { + true + } else { + false + } +} diff --git a/Rust/rustifinity/challenges/sum-of-even-numbers.rs b/Rust/rustifinity/challenges/sum-of-even-numbers.rs new file mode 100644 index 0000000..5588d75 --- /dev/null +++ b/Rust/rustifinity/challenges/sum-of-even-numbers.rs @@ -0,0 +1,9 @@ +pub fn sum_of_evens(start: i32, end: i32) -> i32 { + let mut sum = 0; + for num in start..=end + 1 { + if num % 2 == 0 { + sum += num; + } + } + sum +}