Puzzle: Put a Piece on Square 1! Take a Piece off Square 2!

Bubbler @bubbler@hackers.pub

Problem

You have a game board with 20 empty squares arranged horizontally and 20 game pieces. Each empty square is numbered from 1 to 20, starting from the left. You can perform the following actions as many times as you want:

  • You can place a piece on square 1 or remove a piece from square 1.
  • If there is at least one piece on the board, let's call ii the smallest number of a square that has a piece on it. Then you can place a piece on square i+1i+1 or remove a piece from square i+1i+1.

Is it possible to have pieces on all squares? If so, what is the minimum number of actions required?

Source: The problem content was modified into a puzzle format from BOJ 29225. Пещеры.

Solution

Spoiler To fill all squares, we first need to place a piece on square 20. To place a piece on square 20, we first need to place a piece on square 19, and... to place a piece on square 2, we first need to place a piece on square 1.

Let's figure out how many actions are needed to place a piece on square kk. For convenience, let's denote the action of placing a piece on square kk as k+ and removing a piece as k-.

  • Square 2: 1+ 2+
  • Square 3: 1+ 2+ 1- 3+
  • Square 4: 1+ 2+ 1- 3+ 1+ 2- 1- 4+
  • Square 5: 1+ 2+ 1- 3+ 1+ 2- 1- 4+ 1+ 2+ 1- 3- 1+ 2- 1- 5+

From this pattern, we can infer that the number of actions needed to place a piece on square kk is 2k12^{k-1}.

To explain more logically: to place a piece on square kk, we need to create a state where there is a piece on square k1k-1 and no pieces on squares 1 through k2k-2. Then, to place a piece on square k+1k+1, we need to remove the piece from square k1k-1, which involves almost the same process as placing a piece on square k1k-1 and removing pieces in front of it. The only difference is that the action of placing a piece on square k1k-1 is replaced with removing a piece from square k1k-1.

Now, returning to the original problem, the number of actions needed to place a piece on square 20 is 2192^{19}, and at this point, there is also a piece on square 19, so the next square to fill is square 18. Repeating this process, the answer becomes 219+217++21=2(2201)32^{19} + 2^{17} + \cdots + 2^1 = \frac{2(2^{20} - 1)}{3}.

3

No comments

If you have a fediverse account, you can comment on this article from your own instance. Search https://hackers.pub/ap/articles/019811fa-aaab-70a3-a5a4-150607cfac1b on your instance and reply to it.