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.zelsazgh
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut cont = n; let mut myvec:Vec<u32> = Vec::new(); while cont >0 { myvec.push(cont); cont-=1; } myvec.push(cont); myvec}
oTTeuMsTudio
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while looplet mut v = vec![];let mut n = n;while n > 0 { v.push(n); n -= 1;}v.push(n);v}
VladyslavY
pub fn countdown(n: u32) -> Vec<u32> { (0..n+1).rev().collect::<Vec<u32>>()}
tiagombsilva
pub fn countdown(n: u32) -> Vec<u32> { let mut val = n; let mut vec = Vec::new(); while val > 0 { vec.push(val); val -= 1; } vec.push(0); vec}
digitalresistor
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect::<Vec<u32>>()}
jose-bernardo
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut val = n; let mut arr: Vec<u32> = Vec::new(); while val > 0 { arr.push(val); val -= 1; } arr.push(0); arr}
Maki-SIO
pub fn countdown(n: u32) -> Vec<u32> { let mut count: u32 = n; let mut res = Vec::new(); while count > 0 { res.push(count); count -= 1; } res.push(0); res}
st01011
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while looplet mut v = vec![];let mut n = n;while n > 0 { v.push(n); n -= 1;}v.push(n);v}
radloffl
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut acc: Vec<u32> = Vec::new(); let mut c = n; while c >= 0 { acc.push(c); if c != 0 { c = c - 1; } else { break; } } acc}
just-mephit
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut nums: Vec<u32> = Vec::new(); let mut value = n; if n == 0 { nums.push(0); return nums; } loop { nums.push(value); if value == 1 { break; } value -= 1; } nums.push(0); nums}
carlos-quantexai
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v = vec![]; let mut n = n; while n > 0 { v.push(n); n -= 1; } v.push(n); v}
dslex35
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while looplet mut v = vec![];let mut n = n;while n > 0 { v.push(n); n -= 1;}v.push(n);v}
jhq223
pub fn countdown(n: u32) -> Vec<u32> { let mut n = n; let mut result = vec![]; while n > 0 { result.push(n); n -= 1; } result.push(0); result}
ThatphumCpre
pub fn countdown(n: u32) -> Vec<u32> { let mut v = Vec::new(); for i in (0..=n).rev() { v.push(i); } v}
francisco-cmyk
pub fn countdown(n: u32) -> Vec<u32> { let mut res = Vec::new(); let mut count = n; while count > 0 { res.push(count); if count > 0 { count -= 1 } } res.push(0); return res}
xbarnett
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
mk-comm
pub fn countdown(n: u32) -> Vec<u32> { if n == 0 { return Vec::from([0]) };let mut result = Vec::new();let mut number = n; while number > 0 { result.push(number); if number > 0 { number = number - 1; } }; result.push(0); result // TODO: Implement the countdown using a while loop}
Johnchoi913
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut count = n; let mut result = Vec::new(); while count > 0 { result.push(count); count-= 1; } result.push(count); result}
MosesMp3
pub fn countdown(n: u32) -> Vec<u32> { let mut arr = vec![]; let mut number = n.clone(); loop{ arr.push(number); if number==0{ break; } number-=1; } arr}
lishigushi
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec: Vec<u32> = Vec::new(); let mut counter = n; while counter > 0{ vec.push(counter); counter-=1; } vec.push(0); vec}
majesticalcreature
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(0); output}
sander-b-postnl
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
matei
pub fn countdown(n: u32) -> Vec<u32> { let mut v = Vec::new(); for i in (0..=n).rev() { v.push(i); } v}
i5-650
pub fn countdown(n: u32) -> Vec<u32> { (0..n+1).into_iter().rev().collect::<Vec<u32>>()}
amassare
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect()}
edoardo-morosanu
pub fn countdown(n: u32) -> Vec<u32> { let mut vec: Vec<u32> = Vec::new(); let mut cnt = n; while cnt > 0 { vec.push(cnt); cnt -= 1 } vec.push(0); vec}
zavakid
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect()}
IdoPort
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect()}
IdoPort
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut countdown_vec = Vec::<u32>::new(); let mut n_dynamic = n; while n_dynamic > 0 { countdown_vec.push(n_dynamic); n_dynamic = n_dynamic - 1; } countdown_vec.push(0); countdown_vec}
Ustin
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut res = Vec::<u32>::new(); let mut cnt = n; while cnt != 0 { res.push(cnt); cnt -= 1; } res.push(0); res}
victorchukwuemeka
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v = Vec::new(); let mut s = n; while s > 0{ v.push(s); s-=1; } v.push(0); v}
shankun
pub fn countdown(n: u32) -> Vec<u32> { let mut v : Vec<u32> = vec![n]; while v.len() < n as usize + 1 { v.push(*v.last().unwrap() - 1); } v}
Parallaxes
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v = Vec::new(); let mut t = n; while t > 0 { v.push(t); t -= 1; } v.push(0); v}
Rational1ty
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut timer = Vec::new(); let mut t = n; while t > 0 { timer.push(t); t -= 1; } timer.push(0); return timer;}
retinotopic
pub fn countdown(n: u32) -> Vec<u32> { let mut nn: u32 = n; let mut vc: Vec<u32> = Vec::<u32>::new(); while nn > 0 { vc.push(nn); nn-=1; } vc.push(0); return vc;}
ogaca42
pub fn countdown(mut n: u32) -> Vec<u32> { let mut v = Vec::new(); while n > 0 { v.push(n); n -= 1; } v.push(0); v}
otherJL0
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
pbjarterot
pub fn countdown(mut n: u32) -> Vec<u32> { let mut countdown: Vec<u32> = Vec::new(); // TODO: Implement the countdown using a while loop while n > 0 { countdown.push(n); n-= 1; } countdown.push(0); countdown}
CianciuStyles
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 = 0; while i <= n { result.push(n - i); i += 1; } result}
ayushrawat10
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result = Vec::new(); let mut n = n; while n > 0 { result.push(n); n -= 1; } result.push(0); result}
agegorin
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect::<Vec<u32>>()}
agegorin
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v: Vec<u32> = vec![]; let mut i = n; while i > 0 { v.push(i); i -= 1; } v.push(0); v}
daanbouwman19
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut list = vec![0; (n+1) as usize]; for index in 0..=n { list[index as usize] = n - index; } list}
daanbouwman19
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut list = vec![0; (n+1) as usize]; for index in 0..=n { list[index as usize] = n - index; } list}
damascussteel21
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut t = n; let mut vec = Vec::new(); while t > 0 { vec.push(t); t -= 1; } vec.push(0); vec}
alexromanov
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result: Vec<u32> = Vec::new(); for i in (0..=n).rev() { result.push(i); } result}
LaurentiuStoleriu
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut now = n; let mut myVec = vec![]; while now > 0 { myVec.push(now); now = now - 1; } myVec.push(0); myVec}
mynamesent
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut numbers: Vec<u32> = Vec::new(); let mut i = n; while i > 0 { numbers.push(i); i = i - 1 ; } numbers.push(i); numbers}
oneopane
pub fn countdown(mut i: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut out: Vec<u32> = vec!(); while i > 0 { out.push(i); i -= 1; } out.push(i); out}
oneopane
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut out: Vec<u32> = vec!(); let mut i = n; while i > 0 { out.push(i); i -= 1; } out.push(i); out}