Skip to content

Commit

Permalink
add Problem 21
Browse files Browse the repository at this point in the history
  • Loading branch information
Seasawher committed Mar 20, 2024
1 parent 01de3b5 commit c0847b1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Src.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Src.Problem18
import Src.Problem19
import Src.Problem2
import Src.Problem20
import Src.Problem21
import Src.Problem3
import Src.Problem31
import Src.Problem32
Expand Down
18 changes: 18 additions & 0 deletions Src/Problem21.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/-
# Problem 21
Insert an element at a given position into a list.
-/
variable {α : Type}

def insertAt (e : α) (l : List α) (i : Nat) : List α :=
-- sorry
l.take (i - 1) ++ [e] ++ l.drop (i - 1)
-- sorry

-- The following code is a test case and you should not change it.

example : insertAt "X" ["1", "2", "3", "4"] 2 = ["1", "X", "2", "3", "4"] := rfl

example : insertAt "X" ["1", "2", "3", "4"] 1 = ["X", "1", "2", "3", "4"] := rfl

example : insertAt "X" [] 1 = ["X"] := rfl
4 changes: 4 additions & 0 deletions md/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
* [19: Rotate a list](./build/Problem19.md)
* [20: Remove the K'th element](./build/Problem20.md)

# 21-30: Lists again

* [21: Insert an element](./build/Problem21.md)

# 31-40: Arithmetic

* [31: Prime number detection](./build/Problem31.md)
Expand Down

0 comments on commit c0847b1

Please sign in to comment.