-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0596f69
commit 6862b90
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/- | ||
# Problem 14 | ||
Duplicate the elements of a list. | ||
-/ | ||
|
||
variable {α : Type} | ||
|
||
def dupli (l : List α) : List α := | ||
-- sorry | ||
match l with | ||
| [] => [] | ||
| a :: b => a :: a :: dupli b | ||
-- sorry | ||
|
||
-- The following code is a test case and you should not change it. | ||
|
||
example : dupli [1,2,3] = [1,1,2,2,3,3] := by rfl | ||
|
||
example : dupli ([] : List α) = [] := by rfl | ||
|
||
example : dupli ['a','b','c','c','d'] = ['a','a','b','b','c','c','c','c','d','d'] := by rfl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/- | ||
# Problem 15 | ||
Replicate the elements of a list a given number of times. | ||
-/ | ||
|
||
variable {α : Type} | ||
|
||
def repli (l : List α)(n : Nat) : List α := | ||
-- sorry | ||
match l with | ||
| [] => [] | ||
| a :: b => (solorepl a n) ++ repli b n | ||
where solorepl (x : α)(n : Nat) : List α := | ||
match n with | ||
| 0 => [] | ||
| Nat.succ m => x :: solorepl x m | ||
-- sorry | ||
|
||
-- The following code is a test case and you should not change it. | ||
|
||
example : repli [1,2,3] 3 = [1,1,1,2,2,2,3,3,3] := by rfl | ||
|
||
example : repli [1,2,3] 2 = [1,1,2,2,3,3] := by rfl | ||
|
||
example : repli [1,2,3] 1 = [1,2,3] := by rfl | ||
|
||
example : repli [1,2,3] 0 = [] := by rfl | ||
|
||
example : repli ([] : List α) 255 = [] := by rfl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters