Решение на FMI Buzz от Жечко Попов

Обратно към всички решения

Към профила на Жечко Попов

Резултати

  • 15 точки от тестове
  • 0 бонус точки
  • 15 точки общо
  • 10 успешни тест(а)
  • 0 неуспешни тест(а)

Код

pub fn fizzbuzz(n: usize) -> Vec<String> {
let mut v : Vec<String> = Vec::new();
let mut i : i32 = 1;
let m = n as i32;
while i <= m {
if i % 3 == 0 && i % 5 == 0 {
v.push(String::from("Fizzbuzz"));
}
else if i % 3 == 0 {
v.push(String::from("Fizz"));
}
else if i % 5 == 0 {
v.push(String::from("Buzz"));
}
else {
v.push(i.to_string());
}
i = i + 1;
}
v
}
pub fn custom_buzz(n: usize, k1: u8, k2: u8) -> Vec<String> {
if k1 == 0 || k2 == 0 || k1 == 1 || k2 == 1 {
panic!("Inappropriate input!")
}
let mut v : Vec<String> = Vec::new();
let mut i : i32 = 1;
let m = n as i32;
let d1 = k1 as i32;
let d2 = k2 as i32;
while i <= m {
if i % d1 == 0 && i % d2 == 0 {
v.push(String::from("Fizzbuzz"));
}
else if i % d1 == 0 {
v.push(String::from("Fizz"));
}
else if i % d2 == 0 {
v.push(String::from("Buzz"));
}
else {
v.push(i.to_string());
}
i = i + 1;
}
v
}
pub struct FizzBuzzer {
pub k1: u8,
pub k2: u8,
pub labels: [String; 3],
}
impl FizzBuzzer {
pub fn take(&self, n: usize) -> Vec<String> {
if self.k1 == 0 || self.k2 == 0 || self.k1 == 1 || self.k2 == 1 {
panic!("Inappropriate input!")
}
let mut v : Vec<String> = Vec::new();
let mut i : i32 = 1;
let m = n as i32;
let d1 = self.k1 as i32;
let d2 = self.k2 as i32;
while i <= m {
if i % d1 == 0 && i % d2 == 0 {
v.push(String::from(&self.labels[2]));
}
else if i % d1 == 0 {
v.push(String::from(&self.labels[0]));
}
else if i % d2 == 0 {
v.push(String::from(&self.labels[1]));
}
else {
v.push(i.to_string());
}
i = i + 1;
}
v
}
pub fn change_label(&mut self, index: usize, value: &String) {
if index > 2 {
panic!("Inappropriate size!")
}
self.labels[index] = value.to_string();
}
}

Лог от изпълнението

Compiling solution v0.1.0 (/tmp/d20201028-2816268-1s8afcw/solution)
    Finished test [unoptimized + debuginfo] target(s) in 2.46s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 10 tests
test solution_test::test_change_label_basic ... ok
test solution_test::test_change_label_invalid ... ok
test solution_test::test_classic1 ... ok
test solution_test::test_classic2 ... ok
test solution_test::test_coefficients1 ... ok
test solution_test::test_coefficients2 ... ok
test solution_test::test_coefficients_invalid ... ok
test solution_test::test_struct_basic ... ok
test solution_test::test_struct_invalid ... ok
test solution_test::test_zeroes ... ok

test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests solution

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

История (1 версия и 0 коментара)

Жечко качи първо решение на 28.10.2020 16:10 (преди 9 месеца)