Advertisement
BobMe

wip rnt

Aug 27th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. -- work in progress
  2.  
  3.  
  4. -- roman numeral thing also ur mom big gay if u read this
  5.  
  6. rn = "XX"
  7.  
  8. local sum = 0
  9. local cache = {}
  10.  
  11. function findnum(val)
  12. if val == "I" then
  13. return 1
  14. elseif val == "V" then
  15. return 5
  16. elseif val == "X" then
  17. return 10
  18. elseif val == "L" then
  19. return 50
  20. elseif val == "C" then
  21. return 100
  22. elseif val == "D" then
  23. return 500
  24. elseif val == "M" then
  25. return 1000
  26. end
  27. end
  28.  
  29. local savi = nil
  30. for i=1,#rn do
  31. local val = string.sub(rn,i,i)
  32. local num = findnum(val)
  33. cache[#cache+1] = num
  34. if i ~= 1 then
  35. print("DB: "..cache[#cache-1])
  36. if cache[#cache-1] > cache[#cache] then
  37. print("DB: "..num)
  38. sum = sum + num
  39. else
  40. for i=1,3 do
  41. if cache[#cache-i] > cache[#cache] then
  42.  
  43. else
  44. savi = i
  45. break
  46. end
  47. end
  48. local jum = 0
  49. for i=1,savi do
  50. jum = jum + cache[#cache-i]
  51. end
  52. num = num - jum
  53. sum = sum + num
  54. end
  55. else
  56. sum = sum + num
  57. end
  58. end
  59.  
  60. for i=1,#cache do
  61. print(cache[i])
  62. end
  63. print("________________________\n")
  64. print(sum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement