Coder Social home page Coder Social logo

numerals's Introduction

Numerals

This little utility converts valid Roman numerals to Arabic, and vice-versa.

Conversion from Roman numerals

There are a few rules to observe in checking the validity of a roman number:

  • Having two subtraction in a row is illegal: IXC does not equal 91 (C - (X - I))
  • Having four similar numerals in a row is illegal: 400 should be written as CD (D - C), rather than CCCC
  • But IIII is fine: This is typically used by watchmakers to make the reading of the number 4 easy to read upside down.
  • L and D cannot be repeated: LL should be C, and DD should be M
  • If a certain sequence can be represented with another symbol, it is illegal: LC should be L

Although unicode characters exist, Apostrophus and Vinculum are not supported.

Conversion from Arabic numerals

Due to the rule limiting 4 consecutive Roman numerals, the greatest Arabic numeral is 3999.

Usage

From the command line, use so:

$ numerals IXC
Invalid sequence

$ numerals XCIX
99

$ numerals 198
CXCVIII

Unicode input and output are also supported:

$ numerals ⅬⅡ
52

$ numerals -u 1994
ⅯⅭⅯⅩⅭⅣ

$ numerals --unicode 1994
ⅯⅭⅯⅩⅭⅣ

Known issues

Any value ending in 9, short of 9 itself, will accept invalid input or return invalid output.
For instance, the value XCIX is accepted and returned as 99, although it should reject it and return IC.

However, according to this infoplease page:

According to librarians at NIST, while MIM is more convenient, MCMXCIX is
favored because of earlier precedents with numbers such as 49 (written as
XLIX rather than IL); however, the librarians point out that purists use
neither MIM nor MCMXCIX, opting instead for MCMXCVIIII. The ancient Romans,
they explain, did not use the 20th century convention of IX for the number
nine.

-The Editors

This means that in classical Roman numerals, 4 identical consecutive numerals are allowed, which would change the allowed range from 3999 to 4999.

numerals's People

Contributors

cydanil avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.