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> { // TODO: Implement the countdown using a while loop let mut res = vec![]; let mut nn: i32 = n as i32; while nn >= 0 { res.push(nn as u32); nn -= 1; } res}
pub fn countdown(n: u32) -> Vec<u32> { let mut res = vec![]; let mut nn: i32 = n as i32; while nn >= 0 { res.push(nn as u32); nn -= 1; } res}
pub fn countdown(n: u32) -> Vec<u32> { let mut a = (0..=n).collect::<Vec<u32>>(); a.reverse(); a}
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 (0..=n).map(|x| n - x).collect()}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec = vec![]; let mut i: i32 = n as i32; while i>=0 { vec.push(i as u32); i-=1; } vec}
pub fn countdown(n: u32) -> Vec<u32> { let mut v1: Vec<u32> = Vec::new(); let mut i = n; while i > 0 { v1.push(i); i -= 1; } v1.push(i); return v1}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result: Vec<u32> = vec!(); let mut i = n; while i > 0 { result.push(i); i -= 1; } result.push(0); result}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec :Vec<u32> = Vec::new(); let mut x =n; while x > 0{ vec.push(x); x-=1; } vec.push(0); vec}
pub fn countdown(mut n: u32) -> Vec<u32> { let mut res = vec![]; while n > 0 { res.push(n); n -= 1; } res.push(0); res}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result: Vec<u32> = Vec::new(); let mut count = n; while count != 0 { result.push(count); count -= 1; } result.push(count); result}
pub fn countdown(mut n: u32) -> Vec<u32> { let mut result = vec![n]; while n > 0 { n -= 1; result.push(n); } result}
pub fn countdown(n: u32) -> Vec<u32> { let mut i = n; let mut v = vec![n]; while i > 0 { i -= 1; v.push(i); } v}
pub fn countdown(n: u32) -> Vec<u32> { let mut my_vec: Vec<u32> = vec![]; for i in (0..=n).rev().collect::<Vec<u32>>() { my_vec.push(i) } my_vec}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result = vec![]; let mut n = n; while n > 0 { result.push(n); n-=1; } result.push(n); result}
pub fn countdown(n: u32) -> Vec<u32> { let mut result = vec![]; let mut counter = n; while counter > 0 { result.push(counter); counter -= 1; } result.push(0); result}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut condition = n as i64; let mut result = vec![]; while condition >= 0 { result.push(condition as u32); condition -= 1; } result}
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 n = n; let mut ans = Vec::with_capacity((n + 1) as usize); while n > 0 { ans.push(n); n -= 1; } ans.push(0); ans}
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
pub fn countdown(n: u32) -> Vec<u32> { let mut result = Vec::with_capacity((n+1) as usize); let mut n = n; while n > 0 { result.push(n); n -= 1; } result.push(0); result}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut res = vec![]; let mut n = n; while n > 0 { res.push(n); n -= 1; }; res.push(0); res}
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 result = vec![]; let mut count = n; while count > 0 { result.push(count); count -= 1; } result.push(0); result}
pub fn countdown(n: u32) -> Vec<u32> { let mut ans: Vec<u32> = Vec::new(); let mut limit = n; while limit > 0{ ans.push(limit); limit -= 1; } ans.push(0); ans}
pub fn countdown(n: u32) -> Vec<u32> { let mut v = Vec::new(); let mut i = 0; while i <= n { v.push(n-i); i+=1; } v}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec_countdown = Vec::new(); let mut i = 0; while n >= i{ vec_countdown.push(n-i); i+=1; } vec_countdown}
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
pub fn countdown(n: u32) -> Vec<u32> { let mut ns = (0..=n).collect::<Vec<u32>>(); ns.reverse(); ns}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vect = vec![]; let mut count = n; while count != 0 { vect.push(count); count -=1; } vect.push(0); vect}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut i = n; let mut vec = Vec::new(); while i != 0 { vec.push(i); i -= 1; } vec.push(0); vec}
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 t: Vec<u32> = Vec::new(); let mut i: u32 = n; while i > 0 { t.push(i); i -= 1; } t.push(0); t }
pub fn countdown(n: u32) -> Vec<u32> { let mut current = n; let mut v = Vec::new(); while current > 0 { v.push(current); current -= 1; } v.push(0); v}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect::<Vec<u32>>()}
pub fn countdown(mut n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec = Vec::new(); if n == 0 { vec.push(n); return vec } loop { if n != 0 { vec.push(n); n-=1; } else { vec.push(n); break } } vec}
pub fn countdown(mut n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec = Vec::new(); loop { if n != 0 { vec.push(n); n-=1; } else { vec.push(n); return vec } } vec}
pub fn countdown(mut n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec = Vec::new(); loop { if n != 0 { vec.push(n); n-=1; } else { vec.push(n); break } } vec}
pub fn countdown(mut n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec = Vec::new(); if n == 0 { vec.push(n); return vec } loop { if n != 0 { vec.push(n); n-=1; } else { vec.push(n); break } } vec}
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 result : Vec<u32> = Vec::new(); let mut n = n; while n != 0 { result.push(n); n -= 1; } result.push(n); result}
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()}