Project Euler 89 - Roman Numerals

Official link:

Thought Process

I've got 2 functions, you can use the table on the right to see the small details, you can the official guidelines here

  1. Number_to_roman_numeral(x)

    • This function will take a number, x, and will calculate the Number of M, D, C, L, X, I and will then calculate the nuances, for example, if the number of D > 0 and number of C = 4, this means that we have 900 so we need to append CM instead DCCCC, or if D = 0 and C=4, we append CD instead of CCCC, etc

  2. Roman_numeral_to_number(x)

    • This functions take a roman numeral, x, and will go through the str(x) and start calculating the nuances such as str(x)[i] = C and str(x)[i+1] = M then we we need to add 900 instead of 1000

  3. compute(roman_numerals)

    • This function goes through the list of roman_numerals and calculates the difference between the length of the original roman number and the length of number_to_roman_numeral(roman_numeral_to_number(roman number))

Interactive Code

Follow the instructions to convert a number to Roman numeral or vice versa