What have I done wrong: ```private fun <Long&gt...
# announcements
m
What have I done wrong:
Copy code
private fun <Long> List<Long>.combinationSums(): Sequence<Long> {
    val list = this
    return sequence {
        for (i in 0 until list.count()) {
            for (j in i + 1 until list.count()) {
                val sum: Long = list[j] + list[i]
                yield(sum)
            }
        }
    }.distinct()
}
I am getting a compiler error for the `list[i] + list[j]:
Copy code
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public inline operator fun BigDecimal.plus(other: BigDecimal): BigDecimal defined in kotlin
public inline operator fun BigInteger.plus(other: BigInteger): BigInteger defined in kotlin
public operator fun <T> Array<TypeVariable(T)>.plus(element: TypeVariable(T)): Array<TypeVariable(T)> defined in kotlin.collections
j
You made the function generic, and instead of choosing the usual
<T>
or
<R>
or whatever for the generic type, you chose
<Long>
. So, in your code,
Long
means: some generic type which could be anything. Remove the
<Long>
after `private fun`: your method shouldn’t be generic.
m
ah!
thank you!
n
Happy Advent of Code! BTW: my solution uses
Copy code
fun notSum(v: Long, l: List<Long>): Boolean {
    val s = l.toSet()
    return l.none { v != it * 2 && s.contains(v - it) }
}
m
👍