From d17bc3837bc5a0a08ac22975897327368df7605b Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Thu, 20 Jul 2023 17:30:31 +0200 Subject: [PATCH] Remove impls of deprecated exercises --- exercises/practice/hexadecimal/src/lib.rs | 33 +--------- .../practice/nucleotide-codons/src/lib.rs | 65 ++++++++----------- 2 files changed, 30 insertions(+), 68 deletions(-) diff --git a/exercises/practice/hexadecimal/src/lib.rs b/exercises/practice/hexadecimal/src/lib.rs index f539b3c9c..5692e8518 100644 --- a/exercises/practice/hexadecimal/src/lib.rs +++ b/exercises/practice/hexadecimal/src/lib.rs @@ -1,33 +1,6 @@ -fn parse_hex_digit(c: char) -> Option { - 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 { - 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); } diff --git a/exercises/practice/nucleotide-codons/src/lib.rs b/exercises/practice/nucleotide-codons/src/lib.rs index 0577d8166..f76ce4a97 100644 --- a/exercises/practice/nucleotide-codons/src/lib.rs +++ b/exercises/practice/nucleotide-codons/src/lib.rs @@ -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, 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 + ); +}