lean-golf Lean 4 proof leaderboard

IMO2024 P5

open: first valid proof sets the record

Compfiles · Imo · Apache-2.0
Copyright (c) 2024 Joseph Myers. All rights reserved. Authors: Joseph Myers

Statement

import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.List.ChainOfFn
import Mathlib.Data.List.TakeWhile
import Mathlib.Data.Nat.Dist
import Mathlib.Data.Fintype.Fin
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.IntervalCases
theorem _root_.LeanGolf.compfiles.imo2024_p5 : IsLeast {k | ∃ s : Strategy 2022, s.ForcesWinIn k} answer
Trusted statement context
noncomputable section

public section

namespace Imo2024P5

variable {N : ℕ}

abbrev Cell (N : ℕ) : Type := Fin (N + 2) × Fin (N + 1)

abbrev InteriorRow (N : ℕ) : Type := (Set.Icc 1 ⟨N, by lia⟩ : Set (Fin (N + 2)))

abbrev MonsterData (N : ℕ) : Type := InteriorRow N ↪ Fin (N + 1)

def MonsterData.monsterCells (m : MonsterData N) :
    Set (Cell N) :=
  Set.range (fun x : InteriorRow N ↦ ((x : Fin (N + 2)), m x))

def Adjacent (x y : Cell N) : Prop :=
  Nat.dist x.1 y.1 + Nat.dist x.2 y.2 = 1

structure Path (N : ℕ) where
  /-- The cells on the path. -/
  cells : List (Cell N)
  nonempty : cells ≠ []
  head_first_row : (cells.head nonempty).1 = 0
  last_last_row : (cells.getLast nonempty).1 = Fin.last (N + 1)
  valid_move_seq : cells.IsChain Adjacent

noncomputable def Path.firstMonster (p : Path N) (m : MonsterData N) : Option (Cell N) :=
  let := Classical.propDecidable
  p.cells.find? (fun x ↦ (x ∈ m.monsterCells : Bool))

abbrev Strategy (N : ℕ) : Type := ⦃k : ℕ⦄ → (Fin k → Option (Cell N)) → Path N

noncomputable def Strategy.play (s : Strategy N) (m : MonsterData N) :
    (k : ℕ) → Fin k → Option (Cell N)
| 0 => Fin.elim0
| k + 1 => Fin.snoc (s.play m k) ((s (s.play m k)).firstMonster m)

def Strategy.WinsIn (s : Strategy N) (m : MonsterData N) (k : ℕ) : Prop :=
  none ∈ Set.range (s.play m k)

def Strategy.ForcesWinIn (s : Strategy N) (k : ℕ) : Prop :=
  ∀ m, s.WinsIn m k

abbrev answer : ℕ := 3