IMO 2024 Q5 #
Turbo the snail plays a game on a board with $2024$ rows and $2023$ columns. There are hidden monsters in $2022$ of the cells. Initially, Turbo does not know where any of the monsters are, but he knows that there is exactly one monster in each row except the first row and the last row, and that each column contains at most one monster.
Turbo makes a series of attempts to go from the first row to the last row. On each attempt, he chooses to start on any cell in the first row, then repeatedly moves to an adjacent cell sharing a common side. (He is allowed to return to a previously visited cell.) If he reaches a cell with a monster, his attempt ends and he is transported back to the first row to start a new attempt. The monsters do not move, and Turbo remembers whether or not each cell he has visited contains a monster. If he reaches any cell in the last row, his attempt ends and the game is over.
Determine the minimum value of $n$ for which Turbo has a strategy that guarantees reaching the last row on the $n$th attempt or earlier, regardless of the locations of the monsters.
We follow the solution from the official solutions. To show that $n$ is at least $3$, it is possible that the first cell Turbo encounters in the second row on his first attempt contains a monster, and also possible that the first cell Turbo encounters in the third row on his second attempt contains a monster. To show that $3$ attempts suffice, the first attempt can be used to locate the monster in the second row; if this is not at either side of the board, two more attempts suffice to pass behind that monster and from there go along its column to the last row, while if it is at one side of the board, the second attempt follows a zigzag path such that if it encounters a monster the third attempt can avoid all monsters.
Definitions for setting up the problem #
A row that is neither the first nor the last (and thus contains a monster).
Equations
- Imo2024Q5.InteriorRow N = ↑(Set.Icc 1 ⟨N, ⋯⟩)
Instances For
Data for valid positions of the monsters.
Equations
- Imo2024Q5.MonsterData N = (Imo2024Q5.InteriorRow N ↪ Fin (N + 1))
Instances For
The cells with monsters as a Set, given an injection from rows to columns.
Equations
- m.monsterCells = Set.range fun (x : Imo2024Q5.InteriorRow N) => (↑x, m x)
Instances For
Whether two cells are adjacent.
Equations
- Imo2024Q5.Adjacent x y = ((↑x.1).dist ↑y.1 + (↑x.2).dist ↑y.2 = 1)
Instances For
A valid path from the first to the last row.
- cells : List (Imo2024Q5.Cell N)
The cells on the path.
- nonempty : self.cells ≠ []
- head_first_row : (self.cells.head ⋯).1 = 0
- valid_move_seq : List.Chain' Imo2024Q5.Adjacent self.cells
Instances For
The first monster on a path, or none
.
Equations
- p.firstMonster m = List.find? (fun (x : Imo2024Q5.Cell N) => decide (x ∈ m.monsterCells)) p.cells
Instances For
A strategy, given the results of initial attempts, returns a path for the next attempt.
Equations
- Imo2024Q5.Strategy N = (⦃k : ℕ⦄ → (Fin k → Option (Imo2024Q5.Cell N)) → Imo2024Q5.Path N)
Instances For
Playing a strategy, k attempts.
Equations
Instances For
The predicate for a strategy winning within the given number of attempts.
Instances For
Whether a strategy forces a win within the given number of attempts.
Equations
- s.ForcesWinIn k = ∀ (m : Imo2024Q5.MonsterData N), s.WinsIn m k
Instances For
Reflecting a cell of the board (swapping left and right sides of the board).
Equations
- c.reflect = (c.1, c.2.rev)
Instances For
API definitions and lemmas about MonsterData
#
The row 2, in the form required for MonsterData.
Equations
- Imo2024Q5.row2 hN = ⟨⟨2, ⋯⟩, ⋯⟩
Instances For
Reflecting monster data.
Instances For
The first path element on a row.
Equations
- p.findFstEq r = (List.find? (fun (c : Imo2024Q5.Cell N) => decide (c.1 = r)) p.cells).get ⋯
Instances For
Remove the first cell from a path, if the second cell is also on the first row.
Equations
Instances For
Convert a function giving the cells of a path to a Path
.
Equations
- Imo2024Q5.Path.ofFn f hm hf hl ha = { cells := List.ofFn f, nonempty := ⋯, head_first_row := ⋯, last_last_row := ⋯, valid_move_seq := ⋯ }
Instances For
Reflecting a path.
Equations
Instances For
Proof of lower bound with constructions used therein #
An arbitrary choice of monster positions, which is modified to put selected monsters in desired places.
Equations
- Imo2024Q5.baseMonsterData N = { toFun := fun (x : Imo2024Q5.InteriorRow N) => match x with | ⟨r, ⋯⟩ => ⟨↑r, ⋯⟩, inj' := ⋯ }
Instances For
Positions for monsters with specified columns in the second and third rows (rows 1 and 2).
Equations
- Imo2024Q5.monsterData12 hN c₁ c₂ = (Function.Embedding.setValue (Imo2024Q5.baseMonsterData N) (Imo2024Q5.row2 hN) c₂).setValue (Imo2024Q5.row1 hN) c₁
Instances For
Proof of upper bound and constructions used therein #
The first attempt in a winning strategy, as a function: first pass along the second row to locate the monster there.
Equations
Instances For
The first attempt in a winning strategy, as a Path
.
Equations
- Imo2024Q5.path0 hN = Imo2024Q5.Path.ofFn (Imo2024Q5.fn0 N) ⋯ ⋯ ⋯ ⋯
Instances For
The second attempt in a winning strategy, as a function, if the monster in the second row is not at an edge: pass to the left of that monster then along its column.
Equations
- Imo2024Q5.fn1OfNotEdge hc₁ i = if h : ↑i ≤ 2 then (⟨↑i, ⋯⟩, ⟨↑c₁ - 1, ⋯⟩) else (⟨↑i - 1, ⋯⟩, c₁)
Instances For
The second attempt in a winning strategy, as a function, if the monster in the second row is not at an edge.
Equations
- Imo2024Q5.path1OfNotEdge hc₁ = Imo2024Q5.Path.ofFn (Imo2024Q5.fn1OfNotEdge hc₁) ⋯ ⋯ ⋯ ⋯
Instances For
The third attempt in a winning strategy, as a function, if the monster in the second row is not at an edge: pass to the right of that monster then along its column.
Equations
- Imo2024Q5.fn2OfNotEdge hc₁ i = if h : ↑i ≤ 2 then (⟨↑i, ⋯⟩, ⟨↑c₁ + 1, ⋯⟩) else (⟨↑i - 1, ⋯⟩, c₁)
Instances For
The third attempt in a winning strategy, as a function, if the monster in the second row is not at an edge.
Equations
- Imo2024Q5.path2OfNotEdge hc₁ = Imo2024Q5.Path.ofFn (Imo2024Q5.fn2OfNotEdge hc₁) ⋯ ⋯ ⋯ ⋯
Instances For
The second attempt in a winning strategy, as a function, if the monster in the second row is at the left edge: zigzag across the board so that, if we encounter a monster, we have a third path we know will not encounter a monster.
Equations
Instances For
The second attempt in a winning strategy, as a Path
, if the monster in the second row
is at the left edge.
Equations
- Imo2024Q5.path1OfEdge0 hN = Imo2024Q5.Path.ofFn (Imo2024Q5.fn1OfEdge0 N) ⋯ ⋯ ⋯ ⋯
Instances For
The second attempt in a winning strategy, as a Path
, if the monster in the second row
is at the right edge.
Equations
- Imo2024Q5.path1OfEdgeN hN = (Imo2024Q5.path1OfEdge0 hN).reflect
Instances For
The third attempt in a winning strategy, as a function, if the monster in the second row is at the left edge and the second (zigzag) attempt encountered a monster: on the row before the monster was encountered, move to the following row one place earlier, proceed to the left edge and then along that column.
Equations
Instances For
The third attempt in a winning strategy, as a Path
, if the monster in the second row
is at the left edge and the second (zigzag) attempt encountered a monster.
Equations
- Imo2024Q5.path2OfEdge0 hN hr2 hrN = Imo2024Q5.Path.ofFn (Imo2024Q5.fn2OfEdge0 hrN) ⋯ ⋯ ⋯ ⋯
Instances For
The third attempt in a winning strategy, as a Path
, if the monster in the second row
is at the left edge and the second (zigzag) attempt encountered a monster, version that works
with junk values of r
for convenience in defining the strategy before needing to prove things
about exactly where it can encounter monsters.
Equations
- Imo2024Q5.path2OfEdge0Def hN r = if h : 2 ≤ ↑r ∧ ↑r ≤ N then Imo2024Q5.path2OfEdge0 hN ⋯ ⋯ else Imo2024Q5.path2OfEdge0 hN Imo2024Q5.path2OfEdge0Def.proof_4 hN
Instances For
The third attempt in a winning strategy, as a Path
, if the monster in the second row
is at the right edge and the second (zigzag) attempt encountered a monster.
Equations
- Imo2024Q5.path2OfEdgeNDef hN r = (Imo2024Q5.path2OfEdge0Def hN r).reflect
Instances For
The second attempt in a winning strategy, given the column of the monster in the second row,
as a Path
.
Equations
- Imo2024Q5.path1 hN c₁ = if hc₁ : c₁ = 0 then Imo2024Q5.path1OfEdge0 hN else if ↑c₁ = N then Imo2024Q5.path1OfEdgeN hN else Imo2024Q5.path1OfNotEdge hc₁
Instances For
The third attempt in a winning strategy, given the column of the monster in the second row
and the row of the monster (if any) found in the second attempt, as a Path
.
Equations
- Imo2024Q5.path2 hN c₁ r = if c₁ = 0 then Imo2024Q5.path2OfEdge0Def hN r else if hc₁N : ↑c₁ = N then Imo2024Q5.path2OfEdgeNDef hN r else Imo2024Q5.path2OfNotEdge hc₁N
Instances For
A strategy that wins in three attempts.
Equations
- Imo2024Q5.winningStrategy hN = fun (x : Fin 0 → Option (Imo2024Q5.Cell N)) => Imo2024Q5.path0 hN
- Imo2024Q5.winningStrategy hN = fun (r : Fin 1 → Option (Imo2024Q5.Cell N)) => Imo2024Q5.path1 hN ((r 0).getD 0).2
- Imo2024Q5.winningStrategy hN = fun (r : Fin (n + 2) → Option (Imo2024Q5.Cell N)) => Imo2024Q5.path2 hN ((r 0).getD 0).2 ((r 1).getD 0).1
Instances For
This is to be determined by the solver of the original problem (and much of the difficulty for contestants is in finding this answer rather than spending time attempting to prove a conjectured answer around log₂ 2023).
Equations
Instances For
The final result, combining upper and lower bounds.