import time
from roman_integer import Roman


def check_for_higher_numerals(numeral):
  if "_I_V" in numeral:
    numeral = numeral.replace("_I_V", "MMMM")
  return numeral


if __name__ == "__main__":
  start = time.time()
  roman = Roman()
  numerals = [i.strip()
              for i in open("Data/p089_roman.txt").readlines()]
  old_count = 0
  new_count = 0
  for numeral in numerals:
    old_count += len(numeral)
    int_val = roman.convert_to_integer(numeral, disp=False)
    # print(numeral, int_val)
    proper_roman = roman.convert_to_numeral(int_val, disp=False)
    corrected_roman = check_for_higher_numerals(proper_roman)
    new_count += len(corrected_roman)
  print("Default form count:", old_count)
  print("Minimal form count:", new_count)
  print("Characters saved:", old_count - new_count)
  print("Calculated in:", time.time() - start)
