Sha256: 9cc371acfdb31d693d0bc3d179aa8c125a2d26b5ee395e87be5adbf29397373d
Contents?: true
Size: 1.18 KB
Versions: 9
Compression:
Stored size: 1.18 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
9 entries across 9 versions & 1 rubygems