Let's say there are
To minimize the number of moves, the pistons should push 12 blocks whenever they can. Imagine
Calculating the recursion can be tidious by hand. To de-recurse it, think of the extensions that will be made.
Example for 27 (reads left to right then top to bottom):
12 24 27
12 24 26
12 24 25
12 24
12 23
12 22
12 21
12 20
12 19
12 18
12 17
12 16
12 15
12 14
12 13
12
11
10
9
8
7
6
5
4
3
2
1
You can arrange these in blocks. There's a block with
def piston_sequence(n):
sequence = []
for i in range(n, 0, -1):
for j in range(12, i, 12):
sequence.append(j)
sequence.append(i)
return sequence