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.pub fn countdown(n: u32) -> Vec<u32> { let mut result = Vec::new(); 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 list: Vec<u32> = vec![]; let mut countdown = n.clone(); list.push(countdown); while countdown > 0 { countdown -= 1; list.push(countdown) } list}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut counter = Vec::<u32>::new(); let mut i = n.clone(); while i > 0 { counter.push(i); i -= 1; } counter.push(0); counter}
pub fn countdown(n: u32) -> Vec<u32> { let mut res: Vec<u32> = vec![]; let mut countdown = n.clone(); res.push(countdown); while countdown > 0 { countdown -= 1; res.push(countdown); } return 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> { // TODO: Implement the countdown using a while loop let mut count = n.clone(); let mut countdown: Vec<u32> = Vec::new(); while count > 0 { countdown.push(count); count -= 1; } countdown.push(0); countdown}
pub fn countdown(n: u32) -> Vec<u32> { let mut result = Vec::new(); let mut current = n; while current > 0 { result.push(current); current -= 1; } result.push(0); result}
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).rev().collect()}
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 v: Vec<u32> = vec![]; let mut c = n; while c > 0 { v.push(c); c -= 1; } v.push(0); v}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop if n == 0 { return vec![0]; } let mut counter: u32 = n; let mut result: Vec<u32> = vec![]; 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 if n == 0 { return vec![0] } let mut output = vec![]; let mut count = n; while count != 0 { output.push(count); count -= 1; } output.push(0); output}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec = Vec::new(); let mut i = n; while i > 0 { vec.push(i); i = i - 1; } vec.push(0); vec}
pub fn countdown(n: u32) -> Vec<u32> { let mut vec: Vec<u32> = vec![]; let mut n = n; while n > 0u32 { vec.push(n); n-=1; } vec.push(0u32); vec}
pub fn countdown(n: u32) -> Vec<u32> { let mut n = n; let mut result = vec![n]; while n > 0 { n -= 1; result.push(n); } result}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec = vec![]; let mut nn: i32 = n as i32; while nn >= 0 { vec.push(nn as u32); nn -= 1; } vec}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut output: Vec<u32> = Vec::new(); let mut counter = n; while counter > 0 { output.push(counter); counter -= 1; } output.push(counter); return output;}
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 vec = Vec::new(); let mut i = n; 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 let mut cd = Vec::new(); let mut i = n; while i > 0 { cd.push(i); i -= 1; } cd.push(0); cd}
pub fn countdown(mut n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while looplet mut v:Vec<u32> = Vec::new() ;while n > 0 { v.push(n) ; n -= 1 ;}v.push(0) ;v}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut res:Vec<u32> = vec![]; let mut m = n; while m > 0 { res.push(m); m -= 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!(); let mut i: u32 = n; while i > 0 { v.push(i); i = i -1; } v.push(0); v}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut numbers: Vec<u32> = vec!(); let mut n=n; while n > 0 { numbers.push(n); n = n-1; } numbers.push(0); numbers }
pub fn countdown(mut n: u32) -> Vec<u32> { let mut numbers = vec!(); while n > 0 { numbers.push(n); n = n - 1; } numbers.push(0); numbers}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut res = Vec::new(); 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 (0..=n).rev().collect()}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut array: Vec<u32> = vec![0; (n + 1) as usize]; let mut i = n; while i > 0 { array[(n - i) as usize] = i; i -= 1; } array[n as usize] = 0; array}
pub fn countdown(n: u32) -> Vec<u32> { let mut v: Vec<u32> = vec![n]; let mut index = 0; while v.len() != (n + 1).try_into().unwrap() { v.push(v[index] - 1); index += 1; } v}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut countdown: Vec<u32> = Vec::new(); let mut i = n; while i > 0 { countdown.push(i); i -= 1; } countdown.push(0); countdown}
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_number: u32 = n; while current_number>0 { vec.push(current_number); current_number = current_number -1; } vec.push(0); return 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> { (0..=n).rev().collect()}
pub fn countdown(n: u32) -> Vec<u32> { let mut numbers= Vec::<u32>::new(); let mut count = n; while count > 0 { numbers.push(count); count -= 1; } numbers.push(0); numbers}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut ns: Vec<u32> = vec![]; let mut n_ = n; while true { ns.push(n_); if n_ == 0 { break; } n_ = n_ - 1; } return ns;}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result = Vec::new(); let mut current = n; while current > 0 { result.push(current); current -= 1; } result.push(0); return result;}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut current = n; let mut result = Vec::new(); while current > 0 { result.push(current); current -= 1; } result.push(0); result}
pub fn countdown(n: u32) -> Vec<u32> { let mut result = Vec::<u32>::new(); let mut x = n; while x > 0 { result.push(x); x -= 1; } result.push(x); result}
pub fn countdown(n: u32) -> Vec<u32> { let mut vec = Vec::new(); let mut t = n; while t > 0 { vec.push(t); t -= 1; } vec.push(0); vec}
pub fn countdown( n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v : Vec<u32> = Vec::new() ; let mut n = n as i32 ; while n >= 0 { v.push(n as u32); n-=1; } v}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut countdown = Vec::new(); let mut n = n as i32; while n >= 0 { countdown.push(n as u32); n -= 1; } countdown}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop if n == 0 { return [0].to_vec(); } let mut result: Vec<u32> = vec![]; while result.len() < (n + 1) as usize { result.push( n - result.len() as u32 ) } result}
pub fn countdown(n: u32) -> Vec<u32> { let mut i = n; let mut vector = Vec::new(); while i > 0 { vector.push(i); i -= 1; } vector.push(0); vector}
pub fn countdown(n: u32) -> Vec<u32> { let mut countdown_vec = Vec::new(); let mut counter: u32 = n + 1; while counter > 0 { counter -= 1; countdown_vec.push(counter); } countdown_vec}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop if n == 0 || n < 0{ return vec![0] } let mut vec: Vec<u32> = Vec::new(); for i in 0..=n as u32 { vec.insert(0, i); } vec}
pub fn countdown(n: u32) -> Vec<u32> { let mut res: Vec<u32> = Vec::new(); let mut current = n; while current > 0 { res.push(current); current -= 1; } res.push(0); res}
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut count: i32 = n as i32; let mut vec = Vec::new(); while count > -1 { vec.push(count as u32); count -= 1; } vec}
pub fn countdown(n: u32) -> Vec<u32> { let mut vec = Vec::new(); for i in (0..n + 1).rev(){ vec.push(i); } vec}