How to determine item at a index in pattern

Posted by el.gringogrande on Stack Overflow See other posts from Stack Overflow or by el.gringogrande
Published on 2010-05-21T11:55:16Z Indexed on 2010/05/21 12:00 UTC
Read the original article Hit count: 226

Filed under:

I have the following elements in a list/array

a1,a2,a3

and these elements are used to build another list in a predictable pattern

example

a1,a1,a2,a2,a3,a3,a1,a1,a2,a2,a3,a3...

The pattern may change but I will always know how many times each element repeats and all elements repeats the same number of times. And the elements always show up in the same order.

so another pattern might be

a1,a1,a1,a2,a2,a2,a3,a3,a3,a1,a1,a1,a2,a2,a2,a3,a3,a3...

or

a1,a2,a3,a1,a2,a3

it will never be

a2,a2,a1,a1,a3,a3... or a1,a2,a3,a2,a3,a1 etc

How I determine what element is at any index in the list?

© Stack Overflow or respective owner

Related posts about algorithm