• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

More algorithm help (this time greatly simplified)

Monotaur

Senior member
Hi,

I've posted this before, but not in a concise manner so no one knew what I was talking about... 🙂 Maybe this is more clear?

Anyway, I was wondering if anyone knew of a quick-ish way of solving the following problem:

Given n vectors (V(0), V(1), ..., V(n-1)) each with a maximum size (MS(0), MS(1), ..., MS(n-1)) and having elements from 0 to MS(n-1) - 1 (in ascending order), find the highest value HighVal from 0 to LCM(MS(0), MS(1), ..., MS(n-1))-1 that satisfies the following equation:

HighVal = A(0)*MS(0)+V(0)(B(0)) = A(1)*MS(1)+V(1)(B(1)) = ... = A(n-1)*MS(n-1)+V(n-1)(B(n-1))

Where A(x) is the multiplier of the array and B(x) is the element counter of an array (so, V(10)(12) would return the 12th element in the 10th array).

Does this make sense?

For instance, if I had 3 vectors:

V(0)=[0] (MS(0)=2)
V(1)=[1] (MS(1)=3)
V(2)=[2,3] (MS(2)=4)

The highest HighVal from 0 to LCM(2,3,4)-1 = 0 to 11 is 10.

The methods that I am currently using are pretty slow. BTW, there could be 150 to 300, each with 1000 to 50000 elements).

Thanks!
 
Back
Top