Решение на Сметки с ДНК от Станислав Димов

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

Към профила на Станислав Димов

Резултати

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

Код

pub struct NucleotideCounter {
pub a: usize,
pub c: usize,
pub g: usize,
pub t: usize,
}
impl NucleotideCounter {
fn new() -> NucleotideCounter {
NucleotideCounter {
a: 0,
c: 0,
g: 0,
t: 0,
}
}
}
pub fn counts(dna: &[char]) -> NucleotideCounter {
let mut nucleotide_counter = NucleotideCounter::new();
for c in dna {
match c {
'A' => nucleotide_counter.a += 1,
'C' => nucleotide_counter.c += 1,
'G' => nucleotide_counter.g += 1,
'T' => nucleotide_counter.t += 1,
_ => panic!("Невалиден символ!"),
}
}
nucleotide_counter
}
pub fn dna_complement(dna: &[char]) -> Vec<char> {
let mut result: Vec<char> = Vec::new();
for c in dna {
match c {
'A' => result.push('T'),
'C' => result.push('G'),
'G' => result.push('C'),
'T' => result.push('A'),
_ => panic!("Невалиден символ!"),
}
}
result
}
pub fn reverse_rna_complement(dna: &[char]) -> Vec<char> {
let mut result: Vec<char> = Vec::new();
for c in dna {
match c {
'A' => result.push('U'),
'C' => result.push('G'),
'G' => result.push('C'),
'T' => result.push('A'),
_ => panic!("Невалиден символ!"),
}
}
return result.into_iter().rev().collect();
}

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

Compiling solution v0.1.0 (/tmp/d20220112-2706256-c11udy/solution)
    Finished test [unoptimized + debuginfo] target(s) in 5.62s
     Running tests/solution_test.rs (target/debug/deps/solution_test-4c880d3f0adaac34)

running 12 tests
test solution_test::test_counts_basic ... ok
test solution_test::test_counts_big ... ok
test solution_test::test_counts_panic1 - should panic ... ok
test solution_test::test_counts_panic2 - should panic ... ok
test solution_test::test_counts_zero ... ok
test solution_test::test_dna_complement_big ... ok
test solution_test::test_dna_complement_empty ... ok
test solution_test::test_dna_complement_panic - should panic ... ok
test solution_test::test_reverse_rna_complement_big ... ok
test solution_test::test_reverse_rna_complement_empty ... ok
test solution_test::test_reverse_rna_complement_panic1 - should panic ... ok
test solution_test::test_reverse_rna_complement_panic2 - should panic ... ok

test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

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

Станислав качи първо решение на 25.10.2021 20:48 (преди почти 4 години)

Станислав качи решение на 25.10.2021 21:00 (преди почти 4 години)

-
pub struct NucleotideCounter {
pub a: usize,
pub c: usize,
pub g: usize,
pub t: usize,
}
impl NucleotideCounter {
fn new() -> NucleotideCounter {
NucleotideCounter {
a: 0,
c: 0,
g: 0,
t: 0,
}
}
}
pub fn counts(dna: &[char]) -> NucleotideCounter {
let mut nucleotide_counter = NucleotideCounter::new();
+
for c in dna {
match c {
'A' => nucleotide_counter.a += 1,
'C' => nucleotide_counter.c += 1,
'G' => nucleotide_counter.g += 1,
'T' => nucleotide_counter.t += 1,
_ => panic!("Невалиден символ!"),
}
}
- return nucleotide_counter;
+
+ nucleotide_counter
}
pub fn dna_complement(dna: &[char]) -> Vec<char> {
let mut result: Vec<char> = Vec::new();
for c in dna {
match c {
'A' => result.push('T'),
'C' => result.push('G'),
'G' => result.push('C'),
'T' => result.push('A'),
_ => panic!("Невалиден символ!"),
}
}
- return result;
+
+ result
}
pub fn reverse_rna_complement(dna: &[char]) -> Vec<char> {
let mut result: Vec<char> = Vec::new();
for c in dna {
match c {
'A' => result.push('U'),
'C' => result.push('G'),
'G' => result.push('C'),
'T' => result.push('A'),
- _ => panic!("Невалиден символ!"),
+ _ => panic!("Невалиден символ!"),
}
}
return result.into_iter().rev().collect();
}
-