data/problems/321.yml
---
:id: 321
:name: Swapping Counters
:url: https://projecteuler.net/problem=321
:content: "A horizontal row comprising of 2<var>n</var> + 1 squares has <var>n</var>
red counters placed at one end and <var>n</var> blue counters at the other end,
being separated by a single empty square in the centre. For example, when <var>n</var>
= 3.\n\n ![p321_swapping_counters_1.gif]({{ images_dir }}/p321_swapping_counters_1.gif)\n\nA
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.\n\n ![p321_swapping_counters_2.gif]({{
images_dir }}/p321_swapping_counters_2.gif)\n\nLet M(<var>n</var>) 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.\n\nIt can be verified M(3) = 15, which also happens to be a triangle
number.\n\nIf we create a sequence based on the values of <var>n</var> for which
M(<var>n</var>) is a triangle number then the first five terms would be: \n1, 3,
10, 22, and 63, and their sum would be 99.\n\nFind the sum of the first forty terms
of this sequence.\n\n"