Advertisement
1m1m0

Roman Numeral Generator

Apr 8th, 2024
110
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | Software | 0 0
  1. -- Complete Roman Numeral Translator (REQUIRES VERY BIG BRAIN) --
  2.  
  3. --[[ Some terminology you need to know:
  4.  
  5.     Numerals with || as shown in |IX| means the number is in the thousands.
  6.     Numerals with () as shown in (IX) means the number is in the hundreds of thousands or millions
  7.     For larger numbers that will be added in the future, [] means tens to hundreds of millions, {} for hundreds of millions to billions, <> for tens to hundreds of billions.
  8.    
  9.     Fractional Numerals are divisions of 12 and split into halves or "s"
  10.  
  11.     For more terminologies, I recommend learning how the complete Roman Numerals work!
  12. ]]
  13.  
  14. local startValue = 1 -- I
  15. local increment = 1 -- I
  16. local duration = 10^4 -- |X| or 10,000 [max is 10 million or (X) or 10^7]
  17. local tickSpeed = 0.01 -- seconds for the next increment
  18.  
  19. -- Function to convert a number to extended Roman numerals with subtraction rule and fractions
  20. local function toRoman(num)
  21.     local values = {
  22.         10000000, 9000000, 5000000, 4000000, 1000000, 900000, 500000, 400000, 100000, 90000,
  23.         50000, 40000, 10000, 9000, 5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1
  24.     }
  25.     local numerals = {
  26.         "(X)", "(IX)", "(V)", "(IV)", "(I)", "|IX)", "|D|", "|CD|", "|C|", "|XC|",
  27.         "|L|", "|XL|", "|X|", "|IX|", "|V|", "|IV|", "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"
  28.     }
  29.  
  30.     local fractionSymbols = {"s:·:", "s::", "s∴", "s:", "s·", "s", ":·:", "::", "∴", ":", "·"}
  31.     local fractionValues = {11/12, 5/6, 3/4, 2/3, 7/12, 1/2, 5/12, 1/3, 1/4, 1/6, 1/12}
  32.     local result = ""
  33.     local fractionPart = num % 1 -- Get the fractional part of the number
  34.     num = num - fractionPart -- Remove the fractional part from the number
  35.  
  36.     -- Convert the whole number part to Roman numerals
  37.     for i, value in ipairs(values) do
  38.         while num >= value do
  39.             num = num - value
  40.             if numerals[i] then -- Check if the numeral exists for the index
  41.                 result = result .. numerals[i]
  42.             else
  43.                 print("Error: Index out of bounds for numerals array or Mismatched numerals.") -- Error handler
  44.                 break
  45.             end
  46.         end
  47.     end
  48.  
  49.     -- Convert the fractional part to Roman numerals
  50.     local addedFractions = 0 -- Keep track of added fractions to avoid going over 1
  51.     for i, value in ipairs(fractionValues) do
  52.         while fractionPart >= value and addedFractions + value <= 1 do
  53.             fractionPart = fractionPart - value
  54.             addedFractions = addedFractions + value
  55.             result = result .. fractionSymbols[i]
  56.         end
  57.     end
  58.  
  59.     return result
  60. end
  61.  
  62. -- Function to perform addition over time
  63. local function addOverTime(startValue, increment, duration)
  64.     local currentValue = startValue
  65.     print(toRoman(currentValue))
  66.     for i = 1, duration do
  67.         wait(tickSpeed) -- Wait
  68.         currentValue = currentValue + increment
  69.         print(toRoman(currentValue))
  70.     end
  71. end
  72.  
  73. -- Starting Value, Increment, Tick Duration
  74. addOverTime(startValue, increment, duration)
Advertisement
Comments
  • 1m1m0
    299 days
    # text 0.19 KB | 0 0
    1. |IX) means 900 thousand, or 100 thousand before 1 million. if a numeral has two different indicators, its usually the bridge between large numbers like thousand, million, billion and trillions
Add Comment
Please, Sign In to add comment
Advertisement