Skip to content

Commit

Permalink
Q20
Browse files Browse the repository at this point in the history
  • Loading branch information
csharpython committed Mar 18, 2024
1 parent 1035956 commit cd0f00c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions Src.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Src.Problem12
import Src.Problem14
import Src.Problem15
import Src.Problem2
import Src.Problem20
import Src.Problem3
import Src.Problem31
import Src.Problem32
Expand Down
25 changes: 25 additions & 0 deletions Src/Problem20.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/-
# Problem 20
Remove the K'th element from a list.
-/
variable {α : Type}

def removeAt (l : List α) (n : Nat) : List α :=
-- sorry
match l,n with
| [] , _ => []
| _ , 0 => l
| x :: b , m + 2 => x :: removeAt b (m+1)
| _ :: b , _ => b
-- sorry

-- The following code is a test case and you should not change it.
example : removeAt ['a','b','c','d'] 2 = ['a','c','d'] := rfl

example : removeAt ['a','b','c','d'] 5 = ['a','b','c','d'] := rfl

example : removeAt ['a','b','c','d'] 0 = ['a','b','c','d'] := rfl

example : removeAt ['a'] 1 = [] := rfl

example : removeAt ([] : List α) 1 = [] := rfl
1 change: 1 addition & 0 deletions md/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [12: Decode a run-length encoded list](./build/Problem12.md)
* [14: Duplicate elements](./build/Problem14.md)
* [15: Replicate elements K times](./build/Problem15.md)
* [20: Remove the K'th element](./build/Problem20.md)

# 31-40: Arithmetic

Expand Down

0 comments on commit cd0f00c

Please sign in to comment.