Martin Barth
12/09/2020, 7:08 AMprivate 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]:
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
jbnizet
12/09/2020, 7:51 AM<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.Martin Barth
12/09/2020, 7:51 AMMartin Barth
12/09/2020, 7:52 AMnkiesel
12/09/2020, 7:55 AMfun notSum(v: Long, l: List<Long>): Boolean {
val s = l.toSet()
return l.none { v != it * 2 && s.contains(v - it) }
}
Martin Barth
12/09/2020, 8:05 AM