In this challenge, you will implement a simple countdown timer using a while loop. The goal is to create a function that takes an integer n
and returns a vector containing the countdown from n
to 0.
Write a function countdown(n: u32) -> Vec<u32>
that takes a non-negative integer n
and returns a vector with the numbers from n
to 0.
while
loop to implement the countdown.n
is 0 correctly.let result = countdown(3);
assert_eq!(result, vec![3, 2, 1, 0]);
let result = countdown(0);
assert_eq!(result, vec![0]);
pub fn countdown(n: u32) -> Vec<u32> { let mut steps = Vec::with_capacity((n + 1) as usize); for step in (0..=n).rev() { steps.push(step); } return steps;}
pub fn countdown(n : u32) -> Vec<u32> { let mut result : Vec<u32> = Vec::new(); if n == 0 { return vec![n]; }else{ for i in 0..n +1{ result.push(n-i); } return result; }}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut numbers: Vec<u32> = Vec::new(); let mut n = n; while n != 0 { numbers.push(n); n-=1; } numbers.push(n); numbers}
pub fn countdown(n: u32) -> Vec<u32> { let mut n = n; let mut numbers = Vec::new(); while n > 0 { numbers.push(n); n -= 1; } numbers.push(n); numbers}
pub fn countdown(n: u32) -> Vec<u32> { let mut v = Vec::new(); let mut i: u32 = 0; while i <= n { v.push(n - i); i += 1; } return v;}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut countdown: Vec<u32> = vec![]; let mut count = n; while count > 0 { countdown.push(count); count -= 1; } countdown.push(count); countdown}
pub fn countdown(n: u32) -> Vec<u32> { let mut count:i32 = n as i32; let mut data:Vec<u32> = Vec::new(); while count > -1 { data.push(count as u32); count = count-1; } return data;}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop //(0..=n).rev().collect() let mut result = vec![]; let mut n1 = n; while n1 > 0 { result.push(n1); n1 -= 1; } result.push(0); result}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..n+1).rev().collect()}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut counter = n; let mut result = vec![]; while counter > 0 { result.push(counter); counter -= 1; } result.push(counter); result}
pub fn countdown(n: u32) -> Vec<u32> { let mut res = Vec::with_capacity((n + 1) as usize); for i in 0..=n { res.push(n - i); } res}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n) .rev() .collect()}
pub fn countdown(n: u32) -> Vec<u32> { let mut result = vec![]; let mut n1 = n; while n1 > 0 { result.push(n1); n1 -= 1; } result.push(n1); result}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec = Vec::new(); let mut n = n; while n > 0 { vec.push(n); n -= 1; } vec.push(0); vec}
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut list: Vec<u32> = Vec::new(); let mut i: i32 = n as i32; while i >= 0 { list.push(i as u32); i -= 1; } list}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result: Vec<u32> = Vec::new(); let mut i = n as i32; while i >= 0 { result.push(i as u32); i -= 1; } result}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut array: Vec<u32> = vec![]; let mut x = n; while x > 0 { array.push(x); x -= 1; } array.push(0); array}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v = (0..=n).collect::<Vec<u32>>(); v.reverse(); v}
pub fn countdown(n: u32) -> Vec<u32> { let mut countdown: Vec<u32> = Vec::new(); let mut n: i32 = n as i32; while n >= 0 { countdown.push(n as u32); n = n - 1; } countdown}#[cfg(test)]mod tests { use super::*; #[test] fn it_works() { let result = countdown(3); assert_eq!(result, vec![3, 2, 1, 0]); }}
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect::<Vec<u32>>()}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect::<Vec<u32>>()}
pub fn countdown(n: u32) -> Vec<u32> { if n == 0 { return vec![0]; } let mut n = n; let mut result = vec![n]; while n > 0 { n = n - 1; result.push(n); } result}
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
pub fn countdown(n: u32) -> Vec<u32> { let mut n: i32 = n as i32; let mut cnt: Vec<u32> = Vec::new(); while n >= 0 { cnt.push(n as u32); n-=1; } return cnt; // TODO: Implement the countdown using a while loop}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop(0..=n).rev().collect()}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec = Vec::<u32>::new(); let mut n = n; while n > 0 { vec.push(n); n -= 1; } vec.push(n); vec}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v = vec![]; let mut i = n; while i > 0 { v.push(i); i -= 1; } v.push(0); v}
pub fn countdown(n: u32) -> Vec<u32> { let mut x= n.clone(); let mut count:Vec<u32> = vec![]; while x != 0 { count.insert(count.len(),x); x -= 1; } count.insert(count.len(),0); count}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut countdown_vector: Vec<u32> = Vec::new(); let mut counter: u32 = n; while counter > 0 { countdown_vector.push(counter); counter -= 1; } countdown_vector.push(0); return countdown_vector;}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vector = Vec::new(); for i in 0..n+1 { vector.insert(0,i); } vector}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut count = n; let mut my_vec = vec![n]; while count > 0 { count -= 1; my_vec.push(count); } my_vec}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vector = Vec::new(); for i in (0..n+1) { vector.insert(0, i); } vector}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result: Vec<u32> = Vec::new(); let mut index = n as i32; while index >= 0 { result.push(index.try_into().unwrap()); index -= 1; } result}
pub fn countdown(mut n: u32) -> Vec<u32> { let mut countdown = vec![n]; while n > 0 { n -= 1; countdown.push(n); } countdown }
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
pub fn countdown(n: u32) -> Vec<u32> { let mut nums: Vec<u32> = Vec::with_capacity(n as usize + 1); let mut n = n; while n > 0 { nums.push(n); n -= 1; } nums.push(0); nums}
pub fn countdown(n: u32) -> Vec<u32> { let mut result = Vec::new(); let mut index = n; while index != 0 { result.push(index); index -= 1; } result.push(index); result}
pub fn countdown(mut n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result: Vec<u32> = Vec::new(); result.push(n); while (n > 0) { n = n - 1; result.push(n); } result}
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect::<Vec<u32>>()}
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut countdown = vec!(n); let mut i = n; while i > 0 { i -= 1; countdown.push(i); } countdown}
pub fn countdown(n: u32) -> Vec<u32> { let mut count: u32 = n+1; let mut array: Vec<u32> = Vec::new(); while count > 0 { count -= 1; array.push(count); } array}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut s = n; let mut v= vec![s]; while s > 0 { s -= 1; v.push(s); } v}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut s = n; let mut v= vec![s]; while s > 0 { s -= 1; v.push(s); } v}
pub fn countdown(n: u32) -> Vec<u32> { let mut res = Vec::new(); let mut step = n; while step > 0 { res.push(step); step -= 1; } res.push(step); res}
pub fn countdown(n: u32) -> Vec<u32> { let mut v = Vec::with_capacity((n + 1) as usize); let mut n = n; while n != 0 { v.push(n); n -= 1; } v.push(n); v}
pub fn countdown(n: u32) -> Vec<u32> { let mut v = Vec::with_capacity((n + 1) as usize); let mut n = n; while n != 0 { v.push(n); n -= 1; } v.push(n); v}
pub fn countdown(mut n: u32) -> Vec<u32> { let mut countdown_vector = vec![n]; while n > 0 { n -= 1; countdown_vector.push(n); } countdown_vector}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut myvec = Vec::new(); let mut m = 0; while m <= n { myvec.push(m); m += 1 } myvec.reverse(); myvec}