How to determine an element by index in a template

I have the following items in a list / array

a1, a2, a3

and these elements are used to create another list in a predictable template

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 is repeated, and all elements are repeated the same number of times. And the items are always displayed in the same order.

so another template 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

he will never

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

How do I determine which item is in any index in a list?

, , . . tbe 0 ( integer.maxvalue)

+3
2

:
n -
k -

x-index

[x] == [(x mod (kn)) div k] - , .
, x (x mod (kn)) div k

+4

, , . , , modulo.

-:

determine(index){
  firstelement = list[0]
  i=0;
  for i=0; element.count; i++
    if element != firstelement
      break;
  m = index modulo (i*3)
  switch(m)
    case 0: return 'a1'
    case 1: return 'a2'
    case 2: return 'a3'
}
0

Source: https://habr.com/ru/post/1746551/


All Articles