A horizontal row comprising of squares has red
counters placed at one end and
blue counters at the other end, being separated by a single empty square
in the centre. For example, when .
A counter can move from one square to the next (slide) or can jump
over another counter (hop) as long as the square next to that counter is
unoccupied.
Let represent the minimum
number of moves/actions to completely reverse the positions of the
coloured counters; that is, move all the red counters to the right and
all the blue counters to the left.
It can be verified ,
which also happens to be a triangle number.
If we create a sequence based on the values of n for which is a triangle number then the first
five terms would be:
and , and their sum would be
.
Find the sum of the first forty terms of this sequence.
defgen_solution(): D = 8 base_sol = [(1, 1), (5, 2)] a, b = 3, 1 for x, y in base_sol: yield x, y whileTrue: for i inrange(len(base_sol)): x, y = base_sol[i] x, y = x * a + D * y * b, x * b + y * a yield x, y a, b = 3 * a + 8 * b, a + 3 * b
ls = [] for x, y in gen_solution(): if (x - 1) % 2 == 0and (x - 1) // 2 > 0: ls.append(y - 1) iflen(ls) == N: break ans = sum(ls) print(ans)