I’m not joking, this is just advanced number calculation code I’ve made and which I’m proud of.
Looks like you’re having a good time with this and that’s great. I want to be serious for a moment here. The long form with all the [ elseif ] commands or the version with all the [ or ] statements is not more efficient, in fact far from it. Your passion for this project is refreshing. I think some are taking advantage of that passion to troll you a bit here. There is no need to overcomplicate a simple math function.
The script I’m showing you is basically checking the root of the number. If it is a 0 then it is a even number. If the root is not a 0 then it is an odd number. Any number could be tested with a function like that and this has been around from the time higher math started. It’s not like I came up with this. I’m just showing you this logic in script form.
You clearly have the drive to become an amazing programmer and the passion, like I said, is refreshing. Your time would be better spent moving on from this. There is a lot more to learn and I’m sure you’re going to be great at it pushing as hard as you do.
Thanks for the kind words
Why is it not efficient? I don’t get that part.
This will just bloat the stack with each iteration. Try to stay away for using [ elseif ] and [ or ] so many times in a row like that. When you find yourself using too many there is always a more straightforward way of doing things. It will also push the cycles to achieve it’s goal with larger numbers. Myself I try not to ever go over 4 or 5 [ elseif ] or [ or ] statements. They really don’t come for free, there is a cost for each use reflected in the stack.
Here is a version of doing this you may find interesting. Putting the query down to one line. Creating a command out of it. This is a Server Script with a ModuleScript inside of it.
The main script
local ms = require(script.ModuleScript)
print(ms.isEven(4))
The modulescript
local module = {}
function module.isEven(number)
return number % 2 == 0
end
return module
You could even build up a library of functions like this in the modulescript.
Also I placed the modulescript inside the main script for example convenience.
The main script just needs to have the require part aimed at the modulescript.
this is why bit32
is the best standard library
It just looks reslly complicated and confusing to me
Why is this extremely interesting topic still alive?
It is … a little bit. But it is powerful and worth learning how to do.
Because it’s useful and made with heart.
Sure, you know I made a script like 5 years ago of 20k lines, when I could have just used while true do task.wait() end
, but it was even inefficient because at one time it ended, istead of continuing.
So I respect this advanced number system !
(Add more numbers it will be cooler).
Alright I’m starting working on the 100 million version, unsure if I will be able to do it but wish me luck!
Still working on 100 million version, I’m on like 62 mil rn.
please don’t post troll topics to devforum, also this wouldn’t go in #help-and-feedback:scripting-support it would go in #resources:community-resources
Wdym troll? I’m working on a script for a very long time and you just come to hate on me.
you post a topic called “Help with handwritten advanced number system” when you are shown a simpler system, you call it too complicated, and say that yours is less confusing and more advanced. Your script is not efficient at all, it would lag the game and possibly crash the server when the game is run.
Writing this on mobile, writing mistakes are therefore more likely
It is very obvious that this post is a troll, I have no idea why users are still replying to this.
However if you still insist on doing it the troll way, then I would at least recommend you to use a programming language to automatically produce the troll lua file.
(Although I am sure you already know it as a beginner wouldn’t make this bad of a troll post). If you want to do it in the simplest way, then do the following
local function evenOrOdd(n)
return ({"Even", "Odd"})[n % 2 +1]
end
Super simple. We index an array with the number modulus 2, then add 1.
When a number is even, then the remainder will be zero, however Lua starts indexing at one instead of zero, that is why we have to add 1.
If the number is odd then the remainder will be 1, and with the added 1 it will become 2, meaning that we will get index 2, which is “Odd”.
but OP is not trolling? Stop hating man
i sure do hope this is satire but i’ll reply normally in case it’s not
yeah, but coolyoshi’s script is faster, and can work on way higher numbers, can probably support all the way up to the 2^1024 limit (yours supports up to 1000000, while his supports all the way up to a number with 308 zeros)
your limit: 1000000, maybe higher if you type it in manually but i feel like your studio’s gonna crash before it happens
his limit (below 10 lines of code, everything automatic)
179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137215
this number, yea his limit is this big
it’s just long it’s not advanced at all.
yea but like i said, supports all the way up to the big number 179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137214
crazy ik, and it’s just as reliable believe it or not
i can fix it
function EvenOrOdd(number)
if math.floor(number) ~= number then -- imaginary numbers return "nan", checking if nan equals nan is always false, and now it's just like op's post, only checking integers
print("Unsupported number")
return
end
print(`{number} is {bit32.btest(number, 1) and "odd" or "even"}`) -- i made it shorter lol
end
do you want them to livestream themselves opening the link and crashing or what bro
roblox deprecating a symbol that appears in every single normal coding language??!??!
i can totally read this
gotta love bypassing a connection no normal human being uses
anyways
can someone pull out the benchmarker just to prove the “complicated code” is actually faster?
Maybe instead of checking for every eighteen digit number checking if they’re odd or even, we can grab the last digit of any integer, and use 10 if statements to check whether or not the last digit is even or odd.
local function grabLastDigit(number)
if number == 0 then
return 0
elseif number == 1 then
return 1
elseif number == 2 then
return 2
elseif number == 3 then
return 3
elseif number == 4 then
return 4
elseif number == 5 then
return 5
elseif number == 6 then
return 6
elseif number == 7 then
return 7
elseif number == 8 then
return 8
elseif number == 9 then
return 9
elseif number == 10 then
return 0
elseif number == 11 then
return 1
elseif ... -- Continue this stack
end
end
Then, we can create a function to check if the last digit is even or odd.
local function isEvenOrOdd(digit)
if digit == 0 then
return "even"
elseif digit == 1 then
return "odd"
elseif digit == 2 then
return "even"
elseif digit == 3 then
return "odd"
elseif digit == 4 then
return "even"
elseif digit == 5 then
return "odd"
elseif digit == 6 then
return "even"
elseif digit == 7 then
return "odd"
elseif digit == 8 then
return "even"
elseif digit == 9 then
return "odd"
end
end
Full code:
local function grabLastDigit(number)
if number == 0 then
return 0
elseif number == 1 then
return 1
elseif number == 2 then
return 2
elseif number == 3 then
return 3
elseif number == 4 then
return 4
elseif number == 5 then
return 5
elseif number == 6 then
return 6
elseif number == 7 then
return 7
elseif number == 8 then
return 8
elseif number == 9 then
return 9
elseif number == 10 then
return 0
elseif number == 11 then
return 1
elseif ... -- Continue this stack
end
end
local function isEvenOrOdd(digit)
if digit == 0 then
return "even"
elseif digit == 1 then
return "odd"
elseif digit == 2 then
return "even"
elseif digit == 3 then
return "odd"
elseif digit == 4 then
return "even"
elseif digit == 5 then
return "odd"
elseif digit == 6 then
return "even"
elseif digit == 7 then
return "odd"
elseif digit == 8 then
return "even"
elseif digit == 9 then
return "odd"
end
end
local digit: number = grabLastDigit(55)
print(isEvenOrOdd(digit))
The handwritten code doesn’t even work in Studio, when I copy and paste it Roblox Studio becomes unresponsive. This shows how much memory the code uses. I’ve been waiting for over 5 minutes and studio still isn’t responding (I’m glad I didn’t get the BSOD). The “complicated” code is actually simpler than OP’s “simple” code, only needing a few lines, whereas the “simple” code requires over a million lines. I would estimate that the “simple” code takes 1 million times longer than the “complicated” code.
The code isn’t even complicated at all, it’s just using the modulus operator, all it does it check the remainder when doing division (4 % 2 = 0, 19 % 2 = 1 which means 0 = even, 1 = odd), and only uses a fraction of the memory required with the complicated code. Let’s not forget how most people’s systems will crash with the simple code (low memory on mobile compared to PC), not to mention how you’d even get the code into Studio without it crashing/becoming unresponsive).
I doubt whether the OP knows how much memory usage his script gives.