01-12-2022 04:49 PM
Given a number, and a string of ranges (e.g. "..4,7,11,14-19, 33.."), I want to determine if the number is within the specified range.
Has anyone already built something like that?
01-12-2022 04:56 PM
This might help you partially
01-12-2022 11:18 PM - edited 01-12-2022 11:20 PM
So we have two inputs (or controls):
And one output (boolean), where TRUE means that the number is part of the ranges.
I can think of quite a few solutions. The best probably depends on the answers to the above..
01-13-2022 06:31 AM
@altenbach wrote:
So we have two inputs (or controls):
- A number (Numeric datatype, I guess integer datatype from the example, but not expressively defined. Singed or unsigned? We might have ambiguities defining ranges for negative numbers since the "-" is overloaded).
- A string, defining the ranges.
And one output (boolean), where TRUE means that the number is part of the ranges.
- Can we make any other assumptions (highest possible number, etc.).
- Is speed important?
- What are all possible special characters and their meaning (",", "-", "..", etc.)
- Is the string input often the same with just the number changing (LUT candidate), or do both inputs change often?
- Can we assume that the string input is always well formed, or should we check and possibly return an error?
I can think of quite a few solutions. The best probably depends on the answers to the above..
01-13-2022 06:57 AM - edited 01-13-2022 07:00 AM
Do you have the ability to control the formatting of the ranges? Just having one modifier (e.g. 14-19, 33-, or 14..19, 33.. ) would make it super simple and therefore super fast.
Quick edit if not just do a string replace and that's first step then I would think.
Quick edit 2 it's early and I just restated something that's right above me, you're welcome.
Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.
01-13-2022 07:01 AM
@FireFist-Redhawk wrote:
Do you have the ability to control the formatting of the ranges? Just having one modifier (e.g. 14-19, 33-, or 14..19, 33.. ) would make it super simple and therefore super fast.
Quick edit if not just do a string replace and that's first step then I would think.
Quick edit 2 it's early and I just restated something that's right above me, you're welcome.
At this point, I can define the format of the ranges to be anything.
01-13-2022 07:47 AM - edited 01-13-2022 07:56 AM
I would use hyphen then as it's just one less character. This is what I came up with, feels pretty clean I think. Don't think I inlined it yet.
Edit: Edge case if only one range (no comma). And you can replace the hyphen with something else to get negative number functionality, but Match Pattern doesn't like the double dot it seems.
Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.
01-13-2022 10:10 AM - edited 01-13-2022 10:12 AM
@FireFist-Redhawk wrote:
I would use hyphen then as it's just one less character. This is what I came up with, feels pretty clean I think. Don't think I inlined it yet.
Edit: Edge case if only one range (no comma). And you can replace the hyphen with something else to get negative number functionality, but Match Pattern doesn't like the double dot it seems.
Nice. Here's my variation of it (uses ".." instead of "-"; handles negative numbers; is malleable so it works with any numeric representation)
01-13-2022 05:30 PM
@paul_cardinale wrote:
@FireFist-Redhawk wrote:
I would use hyphen then as it's just one less character. This is what I came up with, feels pretty clean I think. Don't think I inlined it yet.
Edit: Edge case if only one range (no comma). And you can replace the hyphen with something else to get negative number functionality, but Match Pattern doesn't like the double dot it seems.
Nice. Here's my variation of it (uses ".." instead of "-"; handles negative numbers; is malleable so it works with any numeric representation)
Oops, there's a bug: If you wire a numeric array to "Number", it doesn't work properly.
Since I don't need it to work on arrays, I'll put fixing it onto the back burner.