-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Showing
4 changed files
with
117 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
proc append*(list1, list2: seq[int]): seq[int] = | ||
if list2.len == 0: | ||
return list1 | ||
return append(list1 & list2[0], list2[1..^1]) | ||
|
||
proc concatenate*(lists: seq[seq[int]]): seq[int] = | ||
var newList = newSeq[int]() | ||
for list in lists: | ||
newList = append(newList, list) | ||
return newList | ||
|
||
proc filter*(predicate: proc(x: int): bool, list: seq[int]): seq[int] = | ||
var newList = newSeq[int]() | ||
for x in list: | ||
if predicate(x): | ||
newList.add(x) | ||
return newList | ||
|
||
proc length*(list: seq[int]): int = | ||
var len = 0 | ||
for _ in list: | ||
len += 1 | ||
return len | ||
|
||
proc map*(function: proc(x: int): int, list: seq[int]): seq[int] = | ||
var newList = newSeq[int]() | ||
for x in list: | ||
newList.add(function(x)) | ||
return newList | ||
|
||
proc foldl*(function: proc(x, y: int): int, list: seq[int], accumulator: int): int = | ||
if list.len == 0: | ||
return accumulator | ||
return foldl(function, list[1..^1], function(accumulator, list[0])) | ||
|
||
proc foldr*(function: proc(x, y: int): int, list: seq[int], accumulator: int): int = | ||
if list.len == 0: | ||
return accumulator | ||
return function(foldr(function, list[1..^1], accumulator), list[0]) | ||
|
||
proc reverse*(list: seq[int]): seq[int] = | ||
var newList = newSeq[int]() | ||
for x in list: newList.insert(x, 0) | ||
return newList |
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,23 @@ | ||
proc append*(list1, list2: seq[int]): seq[int] = | ||
discard | ||
|
||
proc concatenate*(lists: seq[seq[int]]): seq[int] = | ||
discard | ||
|
||
proc filter*(predicate: proc(x: int): bool, list: seq[int]): seq[int] = | ||
discard | ||
|
||
proc length*(list: seq[int]): int = | ||
discard | ||
|
||
proc map*(function: proc(x: int): int, list: seq[int]): seq[int] = | ||
discard | ||
|
||
proc foldl*(function: proc(x, y: int): int, list: seq[int], accumulator: int): int = | ||
discard | ||
|
||
proc foldr*(function: proc(x, y: int): int, list: seq[int], accumulator: int): int = | ||
discard | ||
|
||
proc reverse*(list: seq[int]): seq[int] = | ||
discard |
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