For context, this is to control multiple stepper motors simultaneously in a high-accuracy application.
Problem statement
Say I have a loop that will run i
iterations. Over the course of those iterations, expression E_x
should evaluate to true
x
times (x <= i
is guaranteed).
Requirements
- E_x
must evaluate to true
exactly x
times
- E_x
must evaluate to true
at more or less evenly spaced intervals*
* "evenly spaced intervals" means that the maximum interval size is minimized
Examples
For: i = 10
, x = 7
E_x
will be true on iterations marked 1
: 1101101101
For: i = 10
, x = 3
E_x
will be true on iterations marked 1
: 0010010010
For: i = 10
, x = 2
E_x
will be true on iterations marked 1
: 0001000100
What is the best (or even "a good") way to have E_x
evaluate to true
at evenly spaced intervals while guaranteeing that it is true exactly x
times?
This question is close to mine, however it assumes that E_x
will always evaluate to true
in the 1st and last iterations, which does not meet my requirements (see 2nd example above).