You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
davhojt 3c6542f6b0 docs(roman_numbers) correct grammar 2 years ago
..
README.md docs(roman_numbers) correct grammar 2 years ago

README.md

roman_numbers

Instructions

Implement the From<u32> trait to create a roman number from a number. The roman number should be in subtractive notation (the common way to write roman number I, II, III, IV, V, VI, VII, VIII, IX, X ...).

Start by defining the digits as RomanDigit (Nulla is 0).

Next define RomanNumber as a wrapper to a vector of RomanDigit, and implement the Trait From<u32>.

Expected Functions and Data Structures

use crate::RomanDigit::*;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum RomanDigit {
	Nulla,
	I,
	V,
	X,
	L,
	C,
	D,
	M,
}

#[derive(Debug, Clone, Debug, PartialEq, Eq)]
pub struct RomanNumber(pub Vec<RomanDigit>);

impl From<u32> for RomanDigit {
}

impl From<u32> for RomanNumber {
}

Usage

Here is a program to test your function.

use roman_numbers::RomanNumber;

fn main() {
	println!("{:?}", RomanNumber::from(32));
	println!("{:?}", RomanNumber::from(9));
	println!("{:?}", RomanNumber::from(45));
	println!("{:?}", RomanNumber::from(0));
}

And its output:

$ cargo run
RomanNumber([X, X, X, I, I])
RomanNumber([I, X])
RomanNumber([X, L, V])
RomanNumber([Nulla])
$