ID:1378462
 
How do you check if a number is within two numbers (including the bounds)?

Most sensible people probably use this:
n >= lower && n <= upper


But what they probably don't know is that DM has an "in-to" ternary operator. It's a ternary operator because it takes three values and gives you one in return, like the ?: operator. Most arithmetic operators are binary operators, like X + Y.

Here's how "in-to" is used.
(n in lower to upper)

It's that easy! It returns true or false, just like the original method.
I had no idea you could do this.
I knew. Cuz SSX.
The "in" operator has a lower order than the logic gates, so it's best to keep the whole expression in parentheses, like you would when using "something in list".
I knew you could do this in a for loop, didn't know you could do it like that...

but is it faster?
In response to Magicsofa
It doesn't matter much, but in my tests, it's up to 0.2 seconds per million tests faster than using 3 operators.
Fascinating.
Okay, that's cool.
pls red book pls
In response to Super Saiyan X
People don't read things unless they're on the front of the forums.
In response to Super Saiyan X
Super Saiyan X wrote:
pls red book pls

war i learnd @
In response to Super Saiyan X
Super Saiyan X wrote:
pls red book pls

I was just thinking, "this is some Red Book type [stuff] right here."
I like this. :)