Rust challenge 44/100 - rust on codewards
Table of content
What is this
The rules of the game are explained in my original post.
44rd Challenge
Challenge
Recently I discovered code wars. It has some fun learning challenges. Today the challenge is to solve some of the code war challenges. I have decided to give this blog a bit of a break and just solve challanges. In this article I will share a view I solved. The reset I will not be sharing.
Solution
Encode DNA, in hindsight and by look at solutions of others, this would have been easier to solve with map
fn dna_strand(dna: &str) -> String {
dna.chars().fold(String::new(), |mut acc, inst| {
match inst {
'T' => acc.push('A'),
'A' => acc.push('T'),
'G' => acc.push('C'),
'C' => acc.push('G'),
_x => panic!("wrongly formatted dna sequence"),
}
acc
})
}
Next I solved a challenge to sort a u64
according to decimal digits.
fn dna_strand(dna: &str) -> String {
use itertools::Itertools;
fn descending_order(x: u64) -> u64 {
x.to_string()
.chars()
.sorted()
.rev()
.collect::<String>()
.parse()
.unwrap()
}
The challenges were fun and it was very helpful to see solutions of others. I may repeat this in the future.