Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
1
local numbers, chars, infamies = {1, 5, 10, 50, 100, 500, 1000}, {"I", "V", "X", "L", "C", "D", "M"}, {} local function ToRomanNumerals(input) input = math.floor(tonumber(input) or 0) if input <= 0 then return input end local result = "" for i = #numbers, 1, -1 do while input - numbers[i] >= 0 and input > 0 do result = result .. chars[i] input = input - numbers[i] end for j = 1, i - 1 do if input - (numbers[i] - numbers[j]) >= 0 and input < numbers[i] and input > 0 and numbers[i] - numbers[j] ~= numbers[j] then result = result .. chars[j] .. chars[i] input = input - (numbers[i] - numbers[j]) break end end end return result end --GET 500 ROMAN NUMS local longest = 0 for i = 0, 500, 1 do local num = ToRomanNumerals(i) if string.len(num) > longest then longest = string.len(num) end table.insert(infamies, {i, num, string.len(num)}) end --SORT THEM BY ROMAN NUM LENGTH table.sort(infamies, function(a, b) return a[3] < b[3] end) --GROUP NUMS BY LENGTH local groups = {} for i=1,longest,1 do table.insert(groups,{}) end for i, v in pairs(infamies) do table.insert(groups[v[3]],v) end --SORT EACH GROUP BY INFAMY NUMBER for i, v in pairs(groups) do table.sort(groups[i], function(a, b) return a[1] < b[1] end) end --PRINT STUFF for i, v in pairs(groups) do print("----------------------------------") for ii,vv in pairs(v) do print(vv[1], vv[2], vv[3]) end end
run
|
edit
|
history
|
help
0
Random number generation with ranges (Lua)
Brainfuck Interpreter (Lua) [reposted]
help with lua number input
Fibonacci in Lua (Inspired)
5+5 == 10
PAID HACK PuBG
Volume of sphere
aaa
Reverse strings function - Lua
hack