from typing import Iterable
from typing import List


def script_param_indexing(array_lengths: Iterable[int],
                          repeat: int) -> List[str]:
  """Creates the script lines that set parameter indices for a run.

  Args:
      array_lengths: The number of parameter settings used for each parameter,
          in order.
      repeat: The number of times to repeat each parameter setting
  Returns:
      A list of script lines that set the parameter indices.
  """
  indexing = []
  indexing.append(f"idx=$((run_index / {repeat}))")
  for i, l in reversed(list(enumerate(array_lengths))):
    indexing.append(f"param_index[{i}]=$((idx % {l}))")
    indexing.append(f"((idx /= {l}))")
  return indexing