-
-
Save zzeroo/86c1a3efcc5651ea761d to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
fn nucleotide_counts(nucleotides: &str) -> HashMap<char, usize> { | |
let mut nucleotide = HashMap::new(); | |
for n in nucleotides.chars() { | |
let counter = nucleotide.entry(n) // gets the given key's corrosponding entry in the map for in-place manipulation | |
.or_insert(0); // ..or insert 0 if its not present already | |
*counter += 1; // Now increment the entry, so it's 1 for all new keys or plus one for all other. | |
} | |
nucleotide | |
} | |
fn count(nucleotide: char) -> usize { | |
let map = nucleotide_counts("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"); | |
match map.get(&nucleotide) { | |
Some(x) => *x, | |
_ => 0, | |
} | |
} | |
fn main() { | |
println!("{:?}", count('')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment