Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tetration Calculator Script with Extended Abbreviations and Infinite Check
- -- Function to calculate tetration
- function tetration(base, exponent)
- local result = 1
- for i = 1, exponent do
- result = base ^ result
- end
- return result
- end
- -- Function to get the abbreviated form of a number
- function getAbbreviation(value)
- if value == math.huge or value == -math.huge then
- return value, ""
- end
- local abbreviations = {"", "K", "M", "B", "T", "Q", "Qn", "Sx", "Sp", "Oc", "Nn", "Dc",
- "Td", "Qad", "Qid", "Sxd", "Spd", "Ocd", "Nvd", "Vg", "Uvg", "Dvg",
- "Tvg", "Qavg", "Qivg", "Sxvg", "Spvg", "Ocvg", "Nnvg", "Tg", "Ut",
- "Dtg", "Tttg", "Qatg", "Qitg", "Sxtg", "Sptg", "Octg", "Ntrg", "Qag",
- "Uqag", "Dqag", "Tqag", "Qaqg", "Qiqg", "Sxqg", "Spqg", "Ocqg", "Nnqg",
- "Qig", "Uqig", "Dqig", "Tqig", "Qaqig", "Qiqig", "Sxqig", "Spqig", "Ocqig", "Nnqig",
- "Sg", "Usg", "Dsg", "Tsg", "Qasg", "Qisg", "Sxsg", "Spsg", "Ocsg", "Nnsg",
- "St", "Ust", "Dst", "Tst", "Qast", "Qist", "Sxst", "Spst", "Ocst", "Nnst",
- "Og", "Uog", "Dog", "Tog", "Qaog", "Qiog", "Sxog", "Spog", "Ocog", "Nnog",
- "Nog", "Unog", "Dnog", "Tnog", "Qanog", "Qinog", "Sxnog", "Spnog", "Ocnog", "Nnnog",
- "C", "Uc", "Dc", "Tc"}
- local idx = 1
- while value >= 1000 and idx < #abbreviations do
- value = value / 1000
- idx = idx + 1
- end
- return value, abbreviations[idx]
- end
- -- Function to round to the nearest hundredths
- function roundToHundredths(num)
- return math.floor(num * 100 + 0.5) / 100
- end
- -- Input values
- local baseValue = 5
- local exponentValue = 3
- -- Calculate tetration
- local resultValue = tetration(baseValue, exponentValue)
- -- Check for infinity
- if resultValue == math.huge or resultValue == -math.huge then
- print("Tetration Result: Infinity (or -Infinity)")
- else
- -- Round to the nearest hundredths
- local roundedResult = roundToHundredths(resultValue)
- -- Get abbreviated form
- local abbreviatedValue, abbreviation = getAbbreviation(roundedResult)
- -- Print results
- print("Base: " .. baseValue)
- print("Exponent: " .. exponentValue)
- print("Tetration Result: " .. roundedResult .. " (" .. abbreviatedValue .. abbreviation .. ")")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement