summaryrefslogtreecommitdiff
path: root/Common/List.lean
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2024-09-24 20:04:26 +0200
committerAndreas Grois <andi@grois.info>2024-09-24 20:04:26 +0200
commitb1c7ab96169f80f62c8f5025cf2ebd74e9128f71 (patch)
tree1ea1882b66edf10cec6281b2d1c71759dba19b7c /Common/List.lean
parent5d08e39abca75b775bb7636973bb9c9a3bb908ac (diff)
Day 12 Part 1.
God, I fell into the premature optimization trap here... But I'm glad I did, that should make part 2 way easier.
Diffstat (limited to 'Common/List.lean')
-rw-r--r--Common/List.lean16
1 files changed, 16 insertions, 0 deletions
diff --git a/Common/List.lean b/Common/List.lean
index b34f1e2..1c029e7 100644
--- a/Common/List.lean
+++ b/Common/List.lean
@@ -54,3 +54,19 @@ def not_empty_iff_size_gt_zero {list : List α} : list.isEmpty = false ↔ list.
match list with
| [] => ⟨nofun, nofun⟩
| l :: ls => ⟨λ_ ↦ (List.length_cons l ls).substr (Nat.succ_pos ls.length), λ_ => rfl⟩
+
+def ne_nil_of_not_empty {list : List α} : list.isEmpty = false ↔ list ≠ [] :=
+ match list with
+ | [] => ⟨nofun, nofun⟩
+ | _ :: _ => ⟨nofun, λ_ ↦ List.isEmpty_cons⟩
+
+def drop_while_length_le (list : List α) (f : α → Bool) : (list.dropWhile f).length ≤ list.length := by
+ unfold dropWhile
+ split
+ case h_1 => exact Nat.le_refl _
+ case h_2 =>
+ split
+ case h_2 => exact Nat.le_refl _
+ case h_1 a as _ _ =>
+ have := drop_while_length_le as f
+ exact Nat.le_trans this (Nat.le_succ as.length)