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.jimlawton
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v = Vec::new(); if n == 0 { v.push(0) } else { for i in (std::ops::Range {start: 0, end: n + 1}) { v.push(n - i); } } v}
woke-developer
pub fn countdown(n: u32) -> Vec<u32> { let mut v = Vec::new(); let mut idx = n; while idx > 0 { v.push(idx); idx -= 1; } v.push(idx); v}
mbergkvist
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut n = n; let mut values = vec![]; while n > 0 { values.push(n); n -=1 } values.push(0); values}
5822791760
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut a: Vec<u32> = Vec::new(); let mut counter = n; while counter > 0 { a.push(counter); counter -= 1; }; a.push(0); return a;}
stdstring
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result: Vec<u32> = Vec::new(); let mut counter = n; while counter > 0 { result.push(counter); counter -= 1; } result.push(0); result}
facat
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut r=Vec::new(); if n==0{ r.push(0); return r; } for v in 0..(n+1){ r.push(v); } r.reverse(); return r;}
xenonminer
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut i = n; let mut res = Vec::new(); while i > 0 { res.push(i); i -= 1; } res.push(0); return res;}
XtebanUy
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut countdown = n; let mut result = Vec::new(); while countdown > 0 { result.push(countdown); countdown -= 1; } result.push(0); result}
mehdihmr
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); return vec;}
MisterWoody
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v: Vec<u32> = Vec::with_capacity(n as usize); let mut value = n; while value > 0 { v.push(value); value -= 1; } v.push(0); v}
ethel-dev
pub fn countdown(n: u32) -> Vec<u32> { let mut cd: Vec<u32> = Vec::with_capacity(n as usize); let mut n = n; while n > 0 { cd.push(n); n -= 1; } cd.push(0); cd}
DivineGod
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result = Vec::with_capacity(n as usize); let mut n = n; while n > 0 { result.push(n); n -= 1; } result.push(n); result}
Algorab
pub fn countdown(n: u32) -> Vec<u32> { (0..n + 1).rev().collect()}
Hannnsen
pub fn countdown(n: u32) -> Vec<u32> { let mut result: Vec<u32> = Vec::new(); let mut i = n; while i > 0 { result.push(i); i = i - 1; } result.push(0); result}
itaygenkin
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec: Vec<u32> = Vec::new(); let mut k: u32 = n; while k > 0 { vec.push(k); k -= 1; } vec.push(k); return vec;}
sroas
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v = Vec::with_capacity(n as usize); let mut i = n; while i > 0 { v.push(i); i -= 1; } v.push(i); v}
felipebalbi
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect()}
danielmpetrov
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
chuyuanlinzi
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect()}
yoakemae
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut v = vec![n]; let mut count: u32 = n; while count > 0 { count -= 1; v.push(count); } return v; }
qiyuan711
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
jw
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
3ok
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut result: Vec<u32> = Vec::new(); let mut current = n; while current > 0 { result.push(current); current -= 1; } result.push(0); result}
nickythorne
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let number = usize::try_from(n).unwrap(); let mut nums: Vec<u32> = Vec::new(); while nums.len() < number + 1 { nums.push((number - nums.len()) as u32); } nums}
chuyuanlinzi
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect()}
DV-13
pub fn countdown(n: u32) -> Vec<u32> { let mut result = vec![]; let mut i = n; while i > 0 { result.push(i); i -= 1; } result.push(0u32); result}
tinthid
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
martin-unit
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vc = Vec::new(); let mut num = n; while num > 0 { vc.push(num); num-=1; } vc.push(0); vc}
RonaldoArayadev
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect()}
mzhutikov
pub fn countdown(n: u32) -> Vec<u32> { let mut countd = Vec::with_capacity((n + 1) as usize); let mut k = n; // Используем цикл, который завершится на 0 while k > 0 { countd.push(k); k -= 1; } // Не забудем добавить 0 в конец обратного отсчета countd.push(0); countd}
dalprahcd
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}
vrzwflng
pub fn countdown(n: u32) -> Vec<u32> { let rng = 0..=n; let vc: Vec<u32> = rng.rev().collect(); vc}
Thymelizabeth
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect()}
Thymelizabeth
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut n = n; let mut result = Vec::new(); while n > 0 { result.push(n); n -= 1; } result.push(n); result}
Thymelizabeth
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut n = n; let mut result = Vec::with_capacity(n as usize + 1); while n > 0 { result.push(n); n -= 1; } result.push(n); result}
devarajang
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut countdown_vec = Vec::<u32>::new(); let mut m = n; while m > 0 { countdown_vec.push(m); m=m-1; } countdown_vec.push(m); return countdown_vec;}
nichideropa
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut countdown: Vec<u32> = vec![]; let mut i: u32 = n; while i > 0 { countdown.push(i); i -= 1; } countdown.push(0); countdown}
akshayabhattarai
pub fn countdown(mut n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut res = vec![]; while n != 0 { res.push(n); n-=1; } res.push(n); res}
jeypiti
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop (0..=n).rev().collect()}
konishu
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); // 最後に 0 を追加 result}
oDqnger
pub fn countdown(n: u32) -> Vec<u32> { let mut countdown_vec = vec![]; for i in (0..n+1).rev() { countdown_vec.push(i); } countdown_vec}
0xsmarter
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut count = n; let mut countdown: Vec<u32> = vec![]; while count != 0 { countdown.push(count); count -= 1; } countdown.push(0); countdown}
madeinheaven91
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut c = n; let mut countdown: Vec<u32> = vec![]; while c != 0 { countdown.push(c); c -= 1; } countdown.push(0); countdown}
madeinheaven91
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut c = n; let mut countdown: Vec<u32> = vec![]; while c != 0 { countdown.push(c); c -= 1; } countdown.push(0); countdown}
joeslow
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}
t3stlab
pub fn countdown(n: u32) -> Vec<u32> { let mut i = n; let mut vec : Vec<u32> = Vec::new(); while i > 0 { vec.push(i); i -= 1; } vec.push(0); vec}
aidan1magee
pub fn countdown(n: u32) -> Vec<u32> { // TODO: Implement the countdown using a while loop let mut vec = Vec::new(); let mut n2 = n; while n2 > 0{ vec.push(n2); n2-=1; } vec.push(0); vec}
ankeetparikh
pub fn countdown(n: u32) -> Vec<u32> { let mut vec = Vec::new(); let mut p = n; while p > 0 { vec.push(p); p -= 1; } vec.push(0); vec}
maxvi
pub fn countdown(n: u32) -> Vec<u32> { let mut result = Vec::new(); let mut i = n; while i >=0 { result.push(i); if i == 0 { break; } i -= 1; } result}
38911BytesFree
pub fn countdown(n: u32) -> Vec<u32> { (0..=n).rev().collect()}