Skip to content
Snippets Groups Projects
Commit 2a0f9314 authored by Ali Sinan Köksal's avatar Ali Sinan Köksal
Browse files

last element of list

parent 7ee59dc9
No related branches found
No related tags found
No related merge requests found
...@@ -68,16 +68,23 @@ object ListMethods { ...@@ -68,16 +68,23 @@ object ListMethods {
// val l = ((l : List) => size(l) == bound).solve // val l = ((l : List) => size(l) == bound).solve
// val lists = for (i <- 1 to nbLists) yield ((l : List) => size(l) == bound).solve // val lists = for (i <- 1 to nbLists) yield ((l : List) => size(l) == bound).solve
val lists = ((l : List) => size(l) == bound && valuesWithin(l, 0, bound - 1)).findAll.toList // val lists = ((l : List) => size(l) == bound && valuesWithin(l, 0, bound - 1)).findAll.toList
val random = new scala.util.Random()
def randomList(s: Int): List = if (s <= 0) Nil() else Cons(random.nextInt(10), randomList(s - 1))
val lists = (1 to nbLists) map (i => randomList(bound))
println("Here are lists:") println("Here are lists:")
println(lists.mkString("\n")) println(lists.mkString("\n"))
// println("Here is its last element: " + last(l)) // println("Here is its last element: " + last(l))
val lastElems = lists.map(l => last(l))
println("last elements:")
println(lastElems)
val added = lists.map(appendElem(_, 42)) // val added = lists.map(appendElem(_, 42))
println("Here are those lists with 42 added to them:") // println("Here are those lists with 42 added to them:")
println(added.mkString("\n")) // println(added.mkString("\n"))
// val sorted = sort(added) // val sorted = sort(added)
// println("Here is the previous list, this time sorted: " + sorted) // println("Here is the previous list, this time sorted: " + sorted)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment