There’s actually an easier way to do it:
local isOdd = nil
function isEven(x: number): boolean
return not isOdd(x)
end
function isOdd(x: number): boolean
return not isEven(x)
end
print(isEven(10)) --true
There’s actually an easier way to do it:
local isOdd = nil
function isEven(x: number): boolean
return not isOdd(x)
end
function isOdd(x: number): boolean
return not isEven(x)
end
print(isEven(10)) --true
This gotta be a zip bomb at this point
Love this thread though
I’ve got a way… I don’t think it’s any better than yours, though… (in fact its a lot worse so prepare for lots of performance issues from this code that you wouldn’t get from yours)
local oddNumbers = {}
local evenNumbers = {}
local nextIsOdd = true
for i = 1, 99e1000000000, 1 do
if nextIsOdd then
oddNumbers[#oddNumbers + 1] = i
else
evenNumbers[#evenNumbers + 1] = i
end
nextIsOdd = if nextIsOdd then false else true
end
local function isEven(number: number)
for _, evenNumber in next, evenNumbers, nil do
if evenNumber == number then
return true
end
end
end
local function isOdd(number: number)
for _, oddNumber in next, oddNumbers, nil do
if oddNumber == number then
return true
end
end
end
print(isEven(100)) --this won't even run because the tables of numbers will be too big.
--I warned you about performance issues, sorry!
extremely inefficient, just use OP’s solution, its way better
look up yandere simulator code review on youtube and you’ll see
extremely inefficient, just use OP’s solution, its way better
they’re comparing the game’s code to your code because both are extremely unoptimized and have a lot of if statements
What? This code isnt unoptimized at all, it uses the roblox’s newest technologies to make it as quick and efficient as it can
if statements and numbers are not new lol, and I’m pretty sure more than 1 gb to check if a number is even is pretty unoptimized
A bit more clean-up to the code or you could call it an alternative.
function EvenOrOdd(number)
return (
number % 2 == 0 and print(number .. " is even")
or print(number .. " is odd")
)
end
No its the best way to calculate if a number is even or odd
It is not the best way, it has a max amount of numbers. Using % is far more optimized and simple.
function getParity(number: number)
if number%2 == 0 then
return "even"
elseif (number+1)%2 == 0 then
return "odd"
else
return "decimal"
end
end
Your code is too complex and not understandable, also it doesnt have a maximum limit as long as you are patient
code being complex and not understandable doesn’t make it bad. I don’t see how my code is complex when my code has 9 lines and the OP’s code has over 1 billion lines.
This is an amazing piece of code, I’d love to see numbers going up to a trillion in future versions!
This provides a fix to this issue I’ve come across multiple times in not being able to make an even/odd numbers checker, heck, the solution was so cold when I opened it up my computer froze.
Your code is so weird you cant even see the individual numbers, what if theres a bug with one number and it returns the wrong result? This isnt a problem with the OPs code since you can manually edit each number
I get you’re trying to be the clown of the show but this is getting old bro… Please drop it
It looks complex sorry.
It’s advanced, thats why it has that many lines
yes
Fine, heres code that gets if a number is even, and has comments to clarify what each step does.
--list of all single digit even numbers.
local evenNumbers = {"2", "4", "6", "8", "0"}
function getParity(No: number)
--checks if the giving "number" is actually a number, if it isn't, print "not a number".
if type(No) == "number" then
--converts the number into a string to make it easier to work with.
local str = tostring(No)
--if a period is found it will print "decimal" and cancel the rest of the function.
if str:find(".") then
print("decimal")
return
end
--gets the last digit
local lastDigit = str:sub(str:len(), str:len())
--variable for wether the number is odd or not (not odd being even).
local odd = true
--if the last digit is found in the list it sets "odd" to false.
if table.find(evenNumbers, lastDigit) then
odd = false
end
--if odd is true, it will print odd, otherwise it will print even.
if odd then
print("odd")
else
print("even")
end
else
print("not a number")
end
end
Why would you need to edit the numbers?
too complicated, adding each number one by one is more secure and fast