I have a list of directions and want to find the next direction when I take a right or left turn. Here is the working code I have:
enum class Turn { R, L }
enum class Direction { N, E, S, W }
val directionsInRightTurnOrder = listOf(Direction.N, Direction.E, Direction.S, Direction.W)
private fun calculateNextHeading(heading: Direction, turn: Turn): Direction {
val currentIndex = directionsInRightTurnOrder.indexOf(heading)
var nextIndex = currentIndex + if (turn == Turn.R) 1 else -1
if (nextIndex >= directionsInRightTurnOrder.size)
nextIndex = directionsInRightTurnOrder.size - nextIndex
if (nextIndex < 0)
nextIndex += directionsInRightTurnOrder.size
return directionsInRightTurnOrder.get(nextIndex)
}
However, this would be so much simpler and easier to read if I could take the directionsInRightTurnOrder list and cycle through it infinitely (and lazily). In Clojure, I can do that, using clojure.core/cycle:
(take 5 (cycle ["a" "b"]))
# ("a" "b" "a" "b" "a")
Another thing that would help is if I could look up in a list using a negative index, like in Ruby or Python:
http://rubyquicktips.com/post/996814716/use-negative-array-indices
Negative index to Python list
Question:
Can I do cycle through a list/collection in Kotlin?
Is there an idiomatic way to do a negative-index-lookup in Kotlin?
Here's cycle:
fun <T : Any> cycle(vararg xs: T): Sequence<T> {
var i = 0
return generateSequence { xs[i++ % xs.size] }
}
cycle("a", "b").take(5).toList() // ["a", "b", "a", "b", "a"]
Here's how you could implement turn application:
enum class Turn(val step: Int) { L(-1), R(1) }
enum class Direction {
N, E, S, W;
fun turned(turn: Turn): Direction {
val mod: (Int, Int) -> Int = { n, d -> ((n % d) + d) % d }
return values()[mod(values().indexOf(this) + turn.step, values().size)]
}
}
Sounds like modulo is what you're looking for -- negative index wrap-around. Couldn't find it in Kotlin's stdlib so I brought my own.
Direction.N
.turned(Turn.R) // E
.turned(Turn.R) // S
.turned(Turn.R) // W
.turned(Turn.R) // N
.turned(Turn.L) // W
Enum#values() and Enum#valueOf(_) are what let you access an enum's members programmatically.
Custom sequence, which repeats indefinitely the given sequence or list can be written quite easily in terms of flatten:
fun <T> Sequence<T>.repeatIndefinitely(): Sequence<T> =
generateSequence(this) { this }.flatten()
fun <T> List<T>.repeatIndefinitely(): Sequence<T> =
this.asSequence().repeatIndefinitely()
You can cycle through a list/collection in Kotlin by generating a sequence that returns the list/collection repeatedly and then flattening it. e.g.:
generateSequence { listOf("a", "b") }.flatten().take(5).toList()
// [a, b, a, b, a]
You can define your own modulo function for coercing both negative and positive numbers to valid indices to access elements in a list (see also Google Guava's IntMath.mod(int, int)):
infix fun Int.modulo(modulus: Int): Int {
if (modulus <= 0) throw ArithmeticException("modulus $modulus must be > 0")
val remainder = this % modulus
return if (remainder >= 0) remainder else remainder + modulus
}
val list = listOf("a", "b", "c", "d")
list[-1 modulo list.size] // last element
list[-2 modulo list.size] // second to last element
list[+9 modulo list.size] // second element
list[-12 modulo list.size] // first element
Paraphrasing the discussion on kotlin Slack:
using List#modulo would make this simpler, but not as elegant as cycle still, since negative indexes will still need to be handled.
One option to implement a cyclical list is a Sequence. However, a custom Sequence will need to be written, or generated using generateSequence. We thought it's an overkill for this situation.
Eventually I went with:
Making Direction aware of next and previous:
enum class Direction {
N, E, S, W;
private val order by lazy { listOf(N, E, S, W) }
fun add(turns: Int): Direction {
val currentIndex = order.indexOf(this)
var nextIndex = (currentIndex + turns) % order.size
return order.possiblyNegativeLookup(nextIndex)
}
fun subtract(turns: Int) = add(-1 * turns)
fun next(): Direction = add(1)
fun previous(): Direction = subtract(1)
}
Extending List with possiblyNegativeLookup:
fun <E> List<E>.possiblyNegativeLookup(i: Int): E {
return if (i < 0) this[this.size + i] else this[i]
}
So the final code turns into:
val nextHeading = if (move.turn == Turn.R) heading.next() else heading.previous()
Related
I am trying to make a list filled with tuples, in a recursive function, so the list can get bigger while iterating. I just don't know how to achieve this in scala.
def tryToClaimPosition(player: Int, horizontal: Int , vertical: Int , list: List[(Int, Int)]): Unit = {
if (vertical == gridsize - 1) {
println(list);
}
if (horizontal < gridsize - 1) {
if (gameBoard(horizontal)(vertical) == player) {
val tuple = (horizontal,vertical)
val list2 = list :: tuple
tryToClaimPosition(player, horizontal + 1, vertical, list2)
else {
tryToClaimPosition(player, horizontal + 1, vertical, list)
}
}
As you see in the snippet above I have a List of tuples and I have a tuple, but I cannot add it.
I'd use immutable list instead, that would be an accumulator. This would be in a more functional way. The function would have no side effect and would return a resulting List:
def tryToClaimPosition(player: Int, horizontal: Int , vertical: Int , list: List[(Int, Int)]): List[(Int, Int)] = {
if (vertical == gridsize - 1) {
list.reverse
}
if (horizontal < gridsize - 1) {
if (gameBoard(horizontal)(vertical) == player) {
val tuple = (horizontal, vertical)
tryToClaimPosition(player,horizontal + 1, vertical, tuple::list)
else {
tryToClaimPosition(player,horizontal + 1, vertical, list)
}
} else Nil
}
Notice, that I have prepended the tuple to the List, because it takes constant time (appending is proportional to the size of the List). That's why I'm returning list.reverse, so that the original ordering is maintained.
Also I asked about the case when horizontal > gridsize - 1. Your program does nothing, so I assume, nothing should be returned, hence Nil in else clause. It is needed, so that there is always a value returned from the function.
Your code has many glaring logic and syntax errors. Most pertinent to your question is that fact that list :: tuple won't compile because the right side of the :: method must be a List.
Use :: to prepend, not append, to a List.
Is there an easy (and maybe even Kotlin way) to generate all permutations of a given list (containing duplicate elements), which:
Keeps the order of the elements
Removes all duplicate elements
Includes all elements
For example:
Given the list: [A, B, C, A, B, D, A], I would expect the following outcomes:
[A, B, C, D], [A, C, B, D], [B, C, A, D], [C, A, B, D], [C, B, A, A], [B, C, D, A],
... (if there are any more combinations)
The following outcomes are not valid:
[A, B, C, A, D] (duplicate A)
[A, B, C, A] (duplicate A and missing D)
[A, C, D, B] (wrong order)
Thanks for your help.
Try this solution below. Heavily recursive but easy to understand (closest to our thinking). One drawback is mem usage.
It's up to you to write a non-recursive one.
fun <T> allPermutations(set: Set<T>): Set<List<T>> {
if (set.isEmpty()) return emptySet()
fun <T> _allPermutations(list: List<T>): Set<List<T>> {
if (list.isEmpty()) return setOf(emptyList())
val result: MutableSet<List<T>> = mutableSetOf()
for (i in list.indices) {
_allPermutations(list - list[i]).forEach{
item -> result.add(item + list[i])
}
}
return result
}
return _allPermutations(set.toList())
}
The input is a set. For your problem, all you need to do is convert your list to a set before calling the method: allPermutations (yourList.toSet())
Code on play.kotlinlang.org
fun main() {
val list = listOf('A', 'B', 'C', 'A', 'B', 'D', 'A')
generatePermutations(list, ::println)
}
/**
* Generates all permutations described in your question
* For the sake of performance it calls [onNextPermutation] for each permutation,
* but it uses the same list to write permutations in,
* so if you need to use these permutations elsewhere copy its parameter by youself
*/
fun <T> generatePermutations(elementsList: List<T>, onNextPermutation: (List<T>) -> Unit) {
if (elementsList.isEmpty()) {
onNextPermutation(emptyList())
return
}
val elementCounts = LinkedHashMap<T, Int>() // We need to remember order in which the elements were added to map
elementsList.forEach {
elementCounts[it] = 1 + (elementCounts[it] ?: 0) // Count our elements
}
val differentElements = elementCounts.keys
val totalPermutationsCount = elementCounts.values.fold(1) { a, b -> a * b }
// Next 3 collections are reused through generator loop for the sake of performance
val takenEntryNumbers = LinkedHashMap<T, Int>() // Number of entry of each element we will take to next permutation
differentElements.forEach { takenEntryNumbers[it] = 0 }
val entriesOfElementViewed = HashMap<T, Int>() // Count of entries of each element we already viewed while iterating elementsList
differentElements.forEach { entriesOfElementViewed[it] = 0 }
val currentPermutation = ArrayList<T>() // Mutable list which we will use to write permutations in
repeat(differentElements.size) { currentPermutation.add(elementsList[0]) } // Just fill it to needed size
repeat(totalPermutationsCount) { // Generate next permutation
var entriesTaken = 0 // Total count of entries taken in this permutation
for (element in elementsList) { // Generate current permutation
if (entriesOfElementViewed[element] == takenEntryNumbers[element]) {
currentPermutation[entriesTaken++] = element
}
entriesOfElementViewed[element] = 1 + (entriesOfElementViewed[element] ?: 0)
}
onNextPermutation(currentPermutation)
// Update collections to start next permutation
differentElements.forEach { entriesOfElementViewed[it] = 0 }
// Generate next permutation of entry numbers, where each entry number is less than element's total count
for (element in differentElements) {
if (1 + (takenEntryNumbers[element] ?: 0) == elementCounts[element]) {
takenEntryNumbers[element] = 0
}
else {
takenEntryNumbers[element] = 1 + (takenEntryNumbers[element] ?: 0)
break
}
}
}
}
Output:
[A, B, C, D]
[B, C, A, D]
[B, C, D, A]
[A, C, B, D]
[C, A, B, D]
[C, B, D, A]
Solves your problem for every list generic type in O(listSize * permutationsCount)
Here's a way to do it in a somewhat functional style.
It starts by collecting a set of "instructions" of the distinct values paired to their occurrence index that should be retained. To do this it maps the unique values to their occurrence counts. Then it folds them into a list of all possible pair combinations. The fold operation starts with an empty set of permutations, and then each unique value multiplies all its possible retained indices with the existing set of permutations.
Then we pass through all the instruction sets to apply the instructions: removing all but one of each unique value from a copy of the original list.
fun <T> getPermutationsWithDistinctValues(original: List<T>): Set<List<T>> {
if (original.isEmpty())
return emptySet()
val permutationInstructions = original.toSet()
.map { it to original.count { x -> x == it } }
.fold(listOf(setOf<Pair<T, Int>>())) { acc, (value, valueCount) ->
mutableListOf<Set<Pair<T, Int>>>().apply {
for (set in acc) for (retainIndex in 0 until valueCount) add(set + (value to retainIndex))
}
}
return mutableSetOf<List<T>>().also { outSet ->
for (instructionSet in permutationInstructions) {
outSet += original.toMutableList().apply {
for ((value, retainIndex) in instructionSet) {
repeat(retainIndex) { removeAt(indexOfFirst { it == value }) }
repeat(count { it == value } - 1) { removeAt(indexOfLast { it == value }) }
}
}
}
}
}
I think the complexity is O(n*mn) where n is the number of distinct values and m is the highest repetition of a distinct value. Same as the other answer, since the worst case number of permutations is mn.
Extension function which returns all permutations
fun <T> List<T>.permutations(): List<List<T>> = if(isEmpty()) listOf(emptyList()) else mutableListOf<List<T>>().also{result ->
for(i in this.indices){
(this - this[i]).permutations().forEach{
result.add(it + this[i])
}
}
}
I am new in sml. I tried to convert int to int list. For example, assume that there is an input 1234, then output is a list like [1,2,3,4]. And my question is, how can I type nested functions in sml? let in end? There is my code.
fun digit (a : int): int =
let
fun size (a) = if a < 0 then nil
else x = Int.toString x then digit s = size(x)
fun insert (num, nil) = [num]
| insert (num,xs) = x :: insert ()
fun convert (a, s) = if s < 0 then nil
else insert (a / (10*(s - 1)), xs)
then convert(a - (10*(s - 1), s - 1)
in
end
Nested functions are just one way to split up your workload in multiple, smaller parts. Another option is non-nested library functions. The main differences are that functions that aren't nested don't inherit its parent's variable scope, so they can only work with their own input, and functions that are nested aren't available anywhere else and can't be re-used. Let's say you're giving this problem a first stab:
fun digit_meh n = if n < 10 then [n] else n mod 10 :: digit_meh (n div 10)
And you realize it isn't doing exactly as you want:
- digit_meh 1234;
> val it = [4, 3, 2, 1] : int list
You could remove the most significant digit first, but the calculation isn't as trivial as n mod 10, since it depends on the number of digits.
You could generate this list and then reverse it:
fun digit n = rev (digit_meh n)
But the function digit_meh isn't particularly useful outside of this function, so it could be hidden using local-in-end or let-in-end:
local
fun digit_meh n = if n < 10 then [n] else n mod 10 :: digit_meh (n div 10)
in
val digit = rev o digit_meh
end
fun digit n =
let fun meh n = if n < 10 then [n] else n mod 10 :: meh (n div 10)
in rev (meh n) end
Do notice that the function meh's copy of n shadows digit's copy of n.
For clarity you could also name the variables differently.
Or you could look at how rev is doing its thing and do that. It basically treats its input as a stack and puts the top element in a new stack recursively so that the top becomes the bottom, much like StackOverflow's logo would look like if it jumped out and landed upside down like a slinky spring:
fun rev L =
let fun rev_stack [] result = result
| rev_stack (x::xs) result = rev_stack xs (x::result)
in rev_stack L [] end
Because the result is accumulated in an additional argument, and rev should only take a single argument, nesting a function with an extra accumulating argument is a really useful trick.
You can mimic this behavior, too:
fun digit N =
let fun digit_stack n result =
if n < 10
then n::result
else digit_stack (n div 10) (n mod 10::result)
in f N [] end
This way, we continue to treat the least significant digit first, but we put it in the stack result which means it ends up at the bottom / end. So we don't need to call rev and save that iteration of the list.
In practice, you don't have to hide helper functions using either local-in-end or let-in-end; while it can be useful in the case of let-in-end to inherit a parent function's scope, it is not necessary to hide your functions once you start using modules with opaque signatures (the :> operator):
signature DIGIT =
sig
val digit : int -> int list
end
structure Digit :> DIGIT =
struct
fun digit_stack n result =
if n < 10
then n::result
else digit_stack (n div 10) (n mod 10::result)
fun digit n = digit_stack n []
end
As this is entered into a REPL, only the relevant function is available outside of the module:
> structure Digit : {val digit : int -> int list}
signature DIGIT = {val digit : int -> int list}
- Digit.digit 1234;
> val it = [1, 2, 3, 4] : int list
fun aFunctionCallingF2F3 someVariables =
let
<define some functions and local variables here>
fun F2 ...
fun F3 ...
val v1 ...
val v2 ...
in
<Make use of the functions/variables you defined above and `someVariables`>
end
For example,
fun areaCirle r:real =
let fun square x:real = x*x
val pi = 3.14
in
pi * square r
end
Or define functions you need to call beforehand if they are not mutually recursive. If they are mutually recursive, you can look up the keyword and.
fun F2 ...
fun F3 ...
fun aFunctionCallingF2F3 = <make use of F2 F3 directly>
For example,
fun square x:real = x * x
fun areaCircle r = square r * 3.14
Note that you cannot do
fun areaCircle r = square r * 3.14
fun square x:real = x * x
square needs to be defined before areaCircle.
I have a List of certain type that I want to reduce based on a condition. I have a type where the Interval is a DateTime interval with a start and an end:
case class MyType(a: Interval, value: Double)
I have got a List[MyType] entries that I want to reduce to a List[MyType] based on MyType that contains same DateTime and value. I do not want to go over the List twice which I already do.
Say I have:
val a = MyType(interval1, 2)
val b = MyType(interval2, 2)
val c = MyType(interval3, 1)
val d = MyType(interval4, 6)
val e = MyType(interval5, 2)
val original = List(a, b, c, d, e)
I have to now reduce the original List based on the following conditions:
1. interval should be continuous, then take the start of the first entry and the end of the second entry
2. the double value should be the same
So assuming that interval1, interval2 are continuous, the result should look like:
val result = Seq(MyType(new Interval(a.interval.start, b.interval.end),2), c, d, e)
Is there a much more elegant solution or an idea?
In the reduce function, check if the condition is true, and if it is, return the current accumulator instead of what would you otherwise compute.
Here's how you would sum only even numbers:
Seq(1,4,6,3).foldLeft(0)( (acc, a) =>
if (a % 2 == 0) acc + a else acc
)
res5: Int = 10
Response to the edited question: It appears you have some conditions that have to hold about the consecuitve elements. Then you can apply the function .sliding.
Seq(a,b,c,d,e).sliding(2).foldLeft(0)(
case (acc, Seq(MyType(ai, a), MyType(bi, b))) =>
if (ai.max == bi.min) acc + a else acc
)
Buuut... You have probably guessed it would not be as performant as you would like. I hope you are not doing any premature optimization, because you know, that's the root of all evil. But if you really need performance, rewrite the code in terms of while loops (fall back to Java).
This should work:
def reduce(xs: List[MyType]) = {
xs match {
case a :: b :: tail =>
if(a.interval.end == b.interval.start && a.value == b.value)
reduce(MyType(new Interval(a.interval.start, b.interval.end) a.value) :: tail)
else
a :: reduce(b :: tail)
case _ => xs
}
}
The if condition might need minor tweaking depending on your exact needs, but the algorithm should work.
Given a list xs
If the first two items a and b can be merged into c, merge them and go back to step 1 with xs = c :: tail
If a and b cannot be merged, try reducing all elements but the first, and append the result to a
Otherwise (list has 1 element or is empty), return xs
Pay attantion that your task could result in multiple distinct solutions, which cannot be further reduced.
So as result you will get a set of solutions: Set[Set[MyType]]
I use Set[MyType] instead of proposed List[MyType] and Seq[MyType] because order is not important and my answer needs possibility to compare different solutions (in order to avoid duplicates).
My answer doesn't make assumptions about order of items, any order is OK.
Besides that in order to simplify the code I have replaced Interval with 2 fields from and to, which can be easily converted.
Here is the code for reduction:
case class MyType(from: Long, to: Long, value: Double)
object MyType {
//Returns all possible varians of reduced source.
//If reduction is not possible, returns empty set.
private def strictReduce(source: Set[MyType]): Set[Set[MyType]] = {
if (source.size <= 1) {Set.empty} else {
val active = source.head //get some item
val otherItems = source.tail //all other items
val reducedWithActive: Set[Set[MyType]] = otherItems.flatMap {
case after if active.to == after.from =>
//we have already found a reduction (active->after),
// so further reductions are not strictly required
reduce(otherItems - after + MyType(active.from, after.to, active.value))
case before if before.to == active.from =>
//we have already found a reduction (before->active),
// so further reductions are not strictly required
reduce(otherItems - before + MyType(before.from, active.to, active.value))
case notContinuos => Set.empty[Set[MyType]]
}
//check if we can reduce items without active
val reducedIgnoringActive = strictReduce(otherItems).
//if so, re-insert active and try to reduce it further, but not strictly anymore
flatMap (reducedOther => reduce(reducedOther + active))
reducedWithActive ++ reducedIgnoringActive
}
}
//Returns all possible varians of reduced source.
//If reduction is not possible, returns source as single result.
private def reduce(source: Set[MyType]): Set[Set[MyType]] = strictReduce(source) match {
case empty if empty.isEmpty => Set(source)
case reduced => reduced
}
//Reduces source, which contains items with different values
def reduceAll(source: Set[MyType]): Set[Set[MyType]] = source.
groupBy(_.value). //divide by values, because they are not merge-able
mapValues(reduce). //reduce for every group
values.reduceLeft((solutionSetForValueA, solutionSetForValueB) =>
//merge solutions for different groups
for(subSolutionForValueA <- solutionSetForValueA;
subSolutionForValueB <- solutionSetForValueB)
yield (subSolutionForValueA ++ subSolutionForValueB) //merge subSolutions
)
}
And here is the sample, which uses it:
object Example extends App {
val source = Set(
MyType(0L, 1L, 1.0),
MyType(1L, 2L, 2.0), //different value
MyType(1L, 3L, 1.0), //competing with next
MyType(1L, 4L, 1.0), //competing with prev
MyType(3L, 5L, 1.0), //joinable with pre-prev
MyType(2L, 4L, 2.0), //joinable with second
MyType(0L, 4L, 3.0) //lonely
)
val solutions: Set[Set[MyType]] = MyType.reduceAll(source)
//here you could choose the best solution (for example by size)
//printing out
solutions.foreach(solution => println(solution.toList.sortBy(_.from).sortBy(_.value).
map(item => s"${item.from}->${item.to}(${item.value})").mkString(", ")))
}
My result is:
0->5(1.0), 1->4(1.0), 1->4(2.0), 0->4(3.0)
0->4(1.0), 1->5(1.0), 1->4(2.0), 0->4(3.0)
Here is what I came up with:
def reduce(accumulator: Seq[MyType], original: Seq[MyType]): Seq[MyType] = original match {
case Nil => accumulator
case head :: xs => {
val found = xs.find(_.timeSpan.getStart().equals(head.timeSpan.getEnd))
if (found.isDefined && found.get.value == head.value) {
reduce(
accumulator :+ (MyType(new Interval(head.timeSpan.getStart, found.get.timeSpan.getEnd), head.value)),
original.diff(Seq(found.get, head))
)
}
else
reduce(
accumulator :+ head,
xs
)
}
}
What is the most efficient way to iterate over two lists (of differing length) backwards in Scala.
So for two lists
List(a,b,c) and List(1,2)
the pairs would be
(c,2) and (b,1)
Note: I would rather not do a reverse of each list.
A simple way is :
List('a','b','c').reverse zip List(1,2).reverse
Reversing the list is O(n) however, if you're worried about efficiency.
According to List's scaladoc, using reverseIterator might be more efficient. That way you don't creat a new list like with reverse, but traverse it as you keep iterating. That'd be :
val it = list1.reverseIterator zip list2.reverseIterator //returns an Iterator you can force
it.toList // List((c,2), (b,1))
Using parallel collections,
def parRevZip (a: List[String], b: List[Int]) = {
val max = Math.max(a.size, b.size)
val n = Math.abs(a.size - b.size)
if (a.size > b.size)
(max to n+1 by -1).par.map { i => (a(i-1), b(i-n-1)) }
else
(max to n+1 by -1).par.map { i => (a(i-n-1), b(i-1)) }
}
Taking into account different index values for possibly different sized lists, this approach fetches and pairs the same number of elements starting from the end of each list.
Performance needs careful evaluation; for small lists, a plain reverse and zipping may prove much simpler and efficient; for large lists, on the contrary, this parallel approach may be of interest.
Code Refinement
def parRevZip[A,B] (a: List[A], b: List[B]) = {
val aSize = a.size
val bSize = b.size
val max = Math.max(aSize, bSize)
val n = Math.abs(aSize - bSize)
if (aSize > bSize)
(max-1 to n by -1).par.map { i => (a(i), b(i-n)) }
else
(max-1 to n by -1).par.map { i => (a(i-n), b(i)) }
}
Using non recursive collections
Convenient immutable collections here where the computation of size is O(1) (or quasi-constant) (see Recursive collections in Scala such as List) include for instance Array.
Hence,
def parRevZip[A,B] (a: Array[A], b: Array[B])
which does not follow any further the requirement of processing lists.
I think you mean this:
val a = List(1, 2, 3)
val b = List(8, 9)
val result = a.reverse zip b.reverse
Here is my attempt at this problem. The original lists a and b are not duplicated. The operation is O(N) due to List.size:
object test extends App {
val a = List("a", "b", "c") //> a : List[String] = List(a, b, c)
val b = List(1, 2) //> b : List[Int] = List(1, 2)
val aSize = a.size //> aSize : Int = 3
val bSize = b.size //> bSize : Int = 2
// find which is smaller and which is bigger list
val (smaller, bigger) = if (aSize < bSize) (a, b) else (b, a)
//> smaller : List[Any] = List(1, 2)
//| bigger : List[Any] = List(a, b, c)
// skip the extra entries from head of bigger list
val truncated = bigger.drop(Math.abs(aSize - bSize))
//> truncated : List[Any] = List(b, c)
val result = if (a == smaller)
smaller.zip(truncated).reverse
else
truncated.zip(smaller).reverse //> result : List[(Any, Any)] = List((c,2), (b,1))
}