Series from For loop (is there a repository for Integer Sequences?)

Made some smalls changes and now it takes care of the 2nd case of “Simple periodic sequence” as function periodicIntSeqRepeatedNTimes(n, lo, hi):

int[] seq4_1_20, seqNeg4_1_20, seq1_10_Neg10;

void setup() {
  seq4_1_20 = periodicIntSeqRepeatedNTimes(4, 20);
  seqNeg4_1_20 = periodicIntSeqRepeatedNTimes(4, -20);
  seq1_10_Neg10 = periodicIntSeqRepeatedNTimes(-1, 10, -10);

  println(str(seq4_1_20));
  println();
  println(str(seqNeg4_1_20));
  println();
  println(str(seq1_10_Neg10));

  exit();
}

static final int[] periodicIntSeqRepeatedNTimes(final int n, final int hi) {
  return periodicIntSeqRepeatedNTimes(n, hi >= 0 ? 1 : -1, hi);
}

static final int[] periodicIntSeqRepeatedNTimes(
  final int n, final int lo, final int hi)
{
  final int
    qty = Math.abs(hi - lo) + 1, 
    len = Math.abs(n) * qty, 
    dir = hi >= lo ? 1 : -1, 
    seq[] = new int[len];

  for (int i = 0; i < len; ++i) seq[i] = i % qty * dir + lo;

  return seq;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10
1 Like