Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Some file #2

Merged
merged 12 commits into from
Mar 17, 2024
Merged
26 changes: 26 additions & 0 deletions Src/Probrem3.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/-
# Problem 3
Find the K'th element of a list.
-/

variable {α : Type}

def element_at (l : List α)(k:Nat) : Option α :=
--sorry
csharpython marked this conversation as resolved.
Show resolved Hide resolved
match k,l with
| _,[] => none
| 0,_ => none
| 1,[a] => some a
| 1,a :: _ => some a
| Nat.succ k,_ :: a => element_at a k
--sorry
-- The following is a test case, you don't need to edit it.
example : element_at ['a','b','c','d','e'] 3 = some 'c' := by rfl

example : element_at ['a','b','c','d','e'] 6 = none := by rfl

example : element_at ['a','b','c','d','e'] 0 = none := by rfl

example : element_at ([] : List α) 0 = none := by rfl

example : element_at [1,2,3] 2 = some 2 := by rfl
22 changes: 22 additions & 0 deletions Src/Probrem4.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/-
# Problem 4
Find the K'th element of a list.
-/

variable {α : Type}

def myLength (l : List α) : Nat :=
--sorry
match l with
| [] => 0
| [_] => 1
| _ :: a => (myLength a).succ
--sorry
-- The following is a test case, you don't need to edit it.
example : myLength [123,456,789] = 3 := by rfl

example : myLength ['L','e','a','n','4'] = 5 := by rfl

example : myLength [False,True,True] = 3 := by rfl

example : myLength ([] : List α) = 0 := by rfl
Loading