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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Src.lean
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Src.Problem1
import Src.Problem2
import Src.Problem3
import Src.Problem4
import Src.README
27 changes: 27 additions & 0 deletions Src/Problem3.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/-
# Problem 3
Find the K'th element of a list.
-/

variable {α : Type}

def elementAt (l : List α) (k : Nat) : Option α :=
csharpython marked this conversation as resolved.
Show resolved Hide resolved
-- sorry
match l, k with
| [], _ => none
| _, 0 => none
| a :: _, 1 => some a
| _ :: a, Nat.succ k => elementAt a k
-- sorry

-- The following is a test case, you don't need to edit it.

example : elementAt ['a', 'b', 'c', 'd', 'e'] 3 = some 'c' := by rfl

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

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

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

example : elementAt [1, 2, 3] 2 = some 2 := by rfl
23 changes: 23 additions & 0 deletions Src/Problem4.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/-
# Problem 4
Find the number of elements in a list.
-/

variable {α : Type}

def myLength (l : List α) : Nat :=
csharpython marked this conversation as resolved.
Show resolved Hide resolved
-- sorry
match l with
| [] => 0
| _ :: 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
6 changes: 5 additions & 1 deletion md/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

* [Problem 1](./Problem1.md)

* [Problem 2](./Problem2.md)
* [Problem 2](./Problem2.md)

* [Problem 3](./Problem3.md)

* [Problem 4](./Problem4.md)
Loading