Coder Social home page Coder Social logo

katas's Introduction

Katas

A bunch of CLIs solving katas:

Setup

To set yourself up, first make sure you have npm and NodeJS installed.

Then clone this repository and create the CLIs links:

git clone [email protected]:lucsgiovanne/katas.git
cd katas
npm link

Available CLIs

In the project directory, you can run:

roman-to-decimal -n <number>

Runs the conversion from roman representation to decimal representation.

Doesn't validate the argument and, therefore, may lead to unexpected behavior on invalid numbers (non-valid roman number between I and MMMCMXCIX).

decimal-to-roman -n <number>

Runs the conversion from decimal representation to roman representation.

Doesn't validate the argument and, therefore, may lead to unexpected behavior on invalid numbers (non-valid decimal number between 1 and 3999).

Tests

npm test

Runs the automated tests.

About the problems

Decimal to roman

The convertion from decimal to roman representation follow the algorithm:

  • Start with the decimal number and an empty string.
  • Iterate over the roman symbols base values in decreasing order (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1) and in each iteration:
    • Divide the remaining number by the iteration base value.
    • Concatenate the string with the corresponding symbol repeated quotient times
    • Update the number with the remainder.

The algorithm correctness is trivially proven by ensuring, by induction, that the final remainder for any number between 1 and 3999 is 0.

Roman to decimal

The convertion from roman to decimal representation follow the algorithm:

  • Start with the roman number and an accumulator.
  • Convert all subtractive notation inside the roman representation to straight summable notation.
  • Walks the summable roman notation of the given number accumulating the decimal convertion for each symbol.

The algorithm correctness become a roman representation definitions consequence by proving the subtractive notation removal algorithm, that's trivially done for numbers between I and MMMCMXCIX.

katas's People

Contributors

giolucasd avatar

Watchers

 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.