A307226 Triangle read by rows: drop and bounce.
0, 0, 1, 0, 1, 2, 0, 1, 3, 2, 0, 4, 1, 3, 2, 0, 4, 5, 1, 3, 2, 0, 4, 6, 5, 1, 3, 2, 7, 0, 4, 6, 5, 1, 3, 2, 7, 0, 4, 6, 5, 1, 3, 2, 8, 7, 0, 4, 6, 5, 1, 3, 2, 9, 8, 7, 0, 4, 6, 5, 1, 3, 10, 2, 9, 8, 7, 0, 4, 6, 5, 1, 11, 3, 10, 2, 9, 8
Offset: 0
Examples
For k = 4: 4 points, bounce on 0, move to the right; 3 points, bounce on 1, move to the right; 2 points, bounce on 3, reverse direction; 1 point, bounce on 1, move to the left; 0 points: k = 4 is inserted between 0 and 1. (Although equal to the next value 0, k has no more points left to bounce over it.) The first iterations: [0]; [0, 1]; [0, 1, 2]; [0, 1, 3, 2]; [0, 4, 1, 3, 2]; [0, 4, 5, 1, 3, 2]; [0, 4, 6, 5, 1, 3, 2]; [7, 0, 4, 6, 5, 1, 3, 2]; [7, 0, 4, 6, 5, 1, 3, 2, 8]; ...
Crossrefs
Cf. A307326.
Programs
-
PARI
process(row, n) = {my(pos = 1, dir = 1, m = n); while (m && (pos >= 1) && (pos <= #row), if (m < row[pos], dir = -dir); pos += dir; m--;); if (pos == 0, return (concat(n, row))); if (pos == #row +1, return (concat(row, n))); if (dir == -1, pos ++); my(nrow = vector(#row+1)); for (k=1, pos-1, nrow[k] = row[k];); nrow[pos] = n; for (k = pos+1, #row+1, nrow[k] = row[k-1];); return (nrow);} tabl(nn) = {row = [0]; print(row); for (n=1, nn, row = process(row, n); print(row););} \\ Michel Marcus, Apr 13 2019
-
Python
seq = [0] for k in range (1, 10): points = k position = seq.index(0) direction = 1 while points > 0 and position >= 0 and position < len(seq): if points < seq[position]: direction *= -1 points -= 1 position += direction else: if position < 0: seq.insert(0, k) elif position == len(seq): seq.append(k) elif points == 0 and direction == 1: seq.insert(position, k) else: seq.insert(position - direction, k) print(seq)
Comments