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 v: Vec<u32> = (0..=n).rev().collect(); v}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect()}
pub fn countdown(mut n: u32) -> Vec<u32> { let mut vec = vec![n]; while n > 0 { n -= 1; vec.push(n); } vec}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut res = vec![]; let mut i = 0; while i <= n { res.push(n-i); i+=1; } res}
pub fn countdown(mut n: u32) -> Vec<u32> { let mut vec = vec![n]; while n > 0 { n -= 1; vec.push(n); } vec}
pub fn countdown(mut n: u32) -> Vec<u32> { let mut result = Vec::with_capacity(n as usize); while n > 0 { result.push(n); n -= 1; } result.push(0); result}
pub fn countdown(n: u32) -> Vec<u32> { let mut a: Vec<u32> = vec!(n); while (a.len() as u32) <= n{ a.push(a.last().unwrap()-1); } a}
pub fn countdown(n: u32) -> Vec<u32> { let mut nums = Vec::new(); let mut current = n; while current > 0 { nums.push(current); current -= 1; } nums.push(0); nums}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut res = Vec::new(); let mut i = n; while i > 0 { res.push(i); i -= 1; } res.push(0); res }
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v: Vec<u32> = vec![]; if n == 0 { v.push(0); return v; } let mut c = n; while c > 0 { v.push(c); if c == 1 { v.push(0); } c -= 1; } v}
pub fn countdown(n: u32) -> Vec<u32> { let mut v: Vec<u32> = Vec::new(); let mut c = n+1; while c > 0 { v.push(c-1); c-=1; } v}
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 list = vec![]; (0..=n).rev().for_each(|i| list.push(i)); list}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v = vec![n]; let mut count = n; while count > 0 { count -= 1; v.push(count); } return v}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec: Vec<u32> = Vec::new(); let mut current: u32 = n; while current > 0 { vec.push(current); current -= 1; } vec.push(0); vec}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec: Vec<u32> = Vec::new(); let mut current: u32 = n; while current > 0 { vec.push(current); current -= 1; } vec.push(0); vec}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut list = vec![]; let mut current = n; while current > 0 { list.push(current); current -= 1; } list.push(0); list}
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 }