-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove impls of deprecated exercises
- Loading branch information
Showing
2 changed files
with
30 additions
and
68 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,6 @@ | ||
fn parse_hex_digit(c: char) -> Option<i64> { | ||
match c { | ||
'0' => Some(0), | ||
'1' => Some(1), | ||
'2' => Some(2), | ||
'3' => Some(3), | ||
'4' => Some(4), | ||
'5' => Some(5), | ||
'6' => Some(6), | ||
'7' => Some(7), | ||
'8' => Some(8), | ||
'9' => Some(9), | ||
'a' => Some(10), | ||
'b' => Some(11), | ||
'c' => Some(12), | ||
'd' => Some(13), | ||
'e' => Some(14), | ||
'f' => Some(15), | ||
_ => None, | ||
} | ||
} | ||
// This exercise is deprecated. | ||
// Consider working on all-your-base instead. | ||
|
||
pub fn hex_to_int(string: &str) -> Option<i64> { | ||
let base: i64 = 16; | ||
|
||
string | ||
.chars() | ||
.rev() | ||
.enumerate() | ||
.fold(Some(0), |acc, (pos, c)| { | ||
parse_hex_digit(c).and_then(|n| acc.map(|acc| acc + n * base.pow(pos as u32))) | ||
}) | ||
unimplemented!("what integer is represented by the base-16 digits {}?", string); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,35 @@ | ||
use std::collections::HashMap; | ||
// This exercise is deprecated. | ||
// Consider working on protein-translation instead. | ||
|
||
pub struct CodonInfo<'a> { | ||
actual_codons: HashMap<&'a str, &'a str>, | ||
} | ||
use std::marker::PhantomData; | ||
|
||
pub fn parse<'a>(pairs: Vec<(&'a str, &'a str)>) -> CodonInfo<'a> { | ||
CodonInfo { | ||
actual_codons: pairs.into_iter().collect(), | ||
} | ||
pub struct CodonsInfo<'a> { | ||
// This field is here to make the template compile and not to | ||
// complain about unused type lifetime parameter "'a". Once you start | ||
// solving the exercise, delete this field and the 'std::marker::PhantomData' | ||
// import. | ||
phantom: PhantomData<&'a ()>, | ||
} | ||
|
||
impl<'a> CodonInfo<'a> { | ||
pub fn name_for(&self, codon: &str) -> Result<&'a str, &'static str> { | ||
if codon.len() != 3 { | ||
return Err("invalid length"); | ||
} | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct Error; | ||
|
||
let mut valid = true; | ||
let lookup: String = codon | ||
.chars() | ||
.map(|l| { | ||
// Get an example of a "letter" represented by the possibly encoded letter. | ||
// Since every codon represented by the compressed notation has to be of | ||
// the desired amino acid just picking one at random will do. | ||
match l { | ||
'A' | 'W' | 'M' | 'R' | 'D' | 'H' | 'V' | 'N' => 'A', | ||
'C' | 'S' | 'Y' | 'B' => 'C', | ||
'G' | 'K' => 'G', | ||
'T' => 'T', | ||
_ => { | ||
valid = false; | ||
' ' | ||
} | ||
} | ||
}) | ||
.collect(); | ||
if !valid { | ||
return Err("invalid char"); | ||
} | ||
impl<'a> CodonsInfo<'a> { | ||
pub fn name_for(&self, codon: &str) -> Result<&'a str, Error> { | ||
unimplemented!( | ||
"Return the protein name for a '{}' codon or Err, if codon string is invalid", | ||
codon | ||
); | ||
} | ||
|
||
// If the input table is correct (which it is) every valid codon is in it | ||
// so unwrap() shouldn't panic. | ||
Ok(self.actual_codons.get(&lookup.as_ref()).unwrap()) | ||
pub fn of_rna(&self, rna: &str) -> Result<Vec<&'a str>, Error> { | ||
unimplemented!("Return a list of protein names that correspond to the '{}' RNA string or Err if the RNA string is invalid", rna); | ||
} | ||
} | ||
|
||
pub fn parse<'a>(pairs: Vec<(&'a str, &'a str)>) -> CodonsInfo<'a> { | ||
unimplemented!( | ||
"Construct a new CodonsInfo struct from given pairs: {:?}", | ||
pairs | ||
); | ||
} |