Skip to content

jvcalderon/h-roman-numbers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Roman Numbers

Build Status Coverage Status

A simple library to convert roman to arabic numbers (and vice versa). It also can check valid roman format.

Installation

The package is not in Hackage repositories yet. You must use stack to install it.

$ stack install

How to use it

Currently you can require the package as follow:

import RomanNumbers

isValidArab

Checks if given value can be converted to roman. Only integers (it checks the type) from 1 to 3999 are valid values.


isValidArab :: Int -> Bool
isValidArab 0 {- Returns (False :: Bool) -}
isValidArab 100  {- Returns (True :: Bool) -}

isValidRoman

Checks if given value can be converted to arab. Only capitalized strings with a valid roman format are valid values.

isValidRoman :: String -> Bool
isValidRoman "" {- Returns (False :: Bool) -}
isValidRoman "IIIX" {- Returns (False :: Bool) -}
isValidRoman "ix" {- Returns (False :: Bool) -}
isValidRoman "XI" {- Returns (True :: Bool) -}

romanToArab

Converts valid roman number to arab.

romanToArab :: String -> (Maybe Int)
romanToArab "IX" {- Returns Just(9) -}
romanToArab "MMM" {- Returns Just(3000) -}
romanToArab "IIIX" {- Returns Nothing -}
romanToArab "" {- Returns Nothing -}

arabToRoman

Converts valid roman number to arab.

arabToRoman :: Int -> (Maybe String)
arabToRoman 12  {- Returns Just("XII") -}
arabToRoman 201 {- Returns Just("CCI") -}
arabToRoman 0 {- Returns Nothing -}
arabToRoman 5000 {- Returns Nothing -}

About

Converts roman numbers to arabic (and vice versa)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors