Sha256: 1eacf6f6b055f55c0d7ee45f124d0d2a02c68294fa28fd4c79a88e9ff61debcb
Contents?: true
Size: 1.15 KB
Versions: 41
Compression:
Stored size: 1.15 KB
Contents
#[derive(Debug, PartialEq)] pub enum Error { InvalidInputBase, InvalidOutputBase, InvalidDigit(u32), } /// /// Convert a number between two bases. /// /// A number is any slice of digits. /// A digit is any unsigned integer (e.g. u8, u16, u32, u64, or usize). /// Bases are specified as unsigned integers. /// /// Return an `Err(.)` if the conversion is impossible. /// The tests do not test for specific values inside the `Err(.)`. /// /// /// You are allowed to change the function signature as long as all test still pass. /// /// /// Example: /// Input /// number: &[4, 2] /// from_base: 10 /// to_base: 2 /// Result /// Ok(vec![1, 0, 1, 0, 1, 0]) /// /// The example corresponds to converting the number 42 from decimal /// which is equivalent to 101010 in binary. /// /// /// Notes: /// * The empty slice ( "[]" ) is equal to the number 0. /// * Never output leading 0 digits. However, your function must be able to /// process input with leading 0 digits. /// pub fn convert(number: &[u32], from_base: u32, to_base: u32) -> Result<Vec<u32>, Error> { unimplemented!("Convert {:?} from base {} to base {}", number, from_base, to_base) }
Version data entries
41 entries across 41 versions & 1 rubygems