Ok, so this one's got me baffled to the point that, I'm not even sure what category this falls in (so if this post is in the wrong one, I apologize for that), but I'm assuming one of the more advanced forms of math.
Unfortunately, I only really remember up to basic, possibly intermediate algebra due to lack of use.
Anyway, what I'm trying to do is find a set number of items out of a total number of items while keeping the intervals as far apart as possible. This is part of a script I'm attempting to write for work, but it's proving more difficult than originally expected as 2 of the variables change quite a bit and my math skills have dropped off a bit, so it's not so much the result as the equation to get the result that I'm having trouble with.
To start, let's say I have a total of Z items of which I need to get X of those items at regular intervals. Now, here's the kicker, the intervals must be in whole numbers. So, for example, say Z = 12 and X = 4; (additionally, 0 will be the first item to grab; think of it more as a stall number than a number of items) I would need the equation to return 0, 4, 8, and 12 as the items to grab. Now, the hard part is when Z and/or X change. Let's say Z = 93 and X = 36; how would I figure which items are the ones I need to grab (the first item being from stall 0 and the 36th from stall 93, the rest being as evenly spaced as possible in between)? Obviously, it's not always going to be a set number of skips before I grab something (like the z=12 x=4 is grab 1, skip 3, grab 1, skip 3, etc). Anyone have any ideas how to write this equation?
I've been staring at this problem so long, it's probably about to slap me across the face, but my mind's so numb towards the issue that I can't see it.
Anyone have any ideas?
Thanks in advance for any assistance!
Edit: Whoopsie... had a typo in there "grab 1 skip 2" instead of "grab 1 skip 3"... sorry, I'm tired and my brain's fried, lol.
Anyway, what I'm trying to do is find a set number of items out of a total number of items while keeping the intervals as far apart as possible. This is part of a script I'm attempting to write for work, but it's proving more difficult than originally expected as 2 of the variables change quite a bit and my math skills have dropped off a bit, so it's not so much the result as the equation to get the result that I'm having trouble with.
To start, let's say I have a total of Z items of which I need to get X of those items at regular intervals. Now, here's the kicker, the intervals must be in whole numbers. So, for example, say Z = 12 and X = 4; (additionally, 0 will be the first item to grab; think of it more as a stall number than a number of items) I would need the equation to return 0, 4, 8, and 12 as the items to grab. Now, the hard part is when Z and/or X change. Let's say Z = 93 and X = 36; how would I figure which items are the ones I need to grab (the first item being from stall 0 and the 36th from stall 93, the rest being as evenly spaced as possible in between)? Obviously, it's not always going to be a set number of skips before I grab something (like the z=12 x=4 is grab 1, skip 3, grab 1, skip 3, etc). Anyone have any ideas how to write this equation?
Anyone have any ideas?
Thanks in advance for any assistance!
Edit: Whoopsie... had a typo in there "grab 1 skip 2" instead of "grab 1 skip 3"... sorry, I'm tired and my brain's fried, lol.
Last edited: