-
Даны два списка чисел. Верните список чисел, присутствующих в обоих исходных списках.
Пример:
mergeLists [0,1,2,3,4] [4,2,40] -> [2,4] mergeLists [0,1,2] [4,5] -> []
-
Дан список чисел
ts
и числоx
. Верните список чисел, в которых присутствует хотя бы одна такая же цифра, как вx
. Систему счисления считать десятичной.
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
import org.junit.Test | |
import java.util.ArrayList | |
interface Whatever | |
fun Whatever.crash() = 2 | |
object obj: Whatever | |
fun Any?.ttt(): Any? = | |
when (this) { |
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
package ru.spbstu.wheels | |
import kotlinx.warnings.Warnings | |
import kotlin.contracts.ExperimentalContracts | |
import kotlin.contracts.contract | |
import kotlin.properties.ReadOnlyProperty | |
import kotlin.properties.ReadWriteProperty | |
import kotlin.reflect.KProperty | |
abstract class GetterAndSetterBuilderEmpty<T> { |
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
package ru.spbstu.draw | |
import ru.spbstu.wheels.aStarSearch | |
import java.awt.* | |
import java.awt.event.ActionEvent | |
import java.awt.event.MouseAdapter | |
import java.awt.event.MouseEvent | |
import java.awt.event.MouseWheelEvent | |
import java.awt.geom.* | |
import javax.swing.* |
Clone class 0:
https://github.com/Ilya1998/KotlinAsFirst2016/blob/master/src/lesson4/task1/List.kt#L242-L258
https://github.com/KuzinaMari/KotlinAsFirst2016/blob/master/src/lesson4/task1/List.kt#L296-L312
Clone class 1:
https://github.com/Perepicica/KotlinAsFirst2016/blob/master/src/lesson5/task1/Parse.kt#L103-L121
https://github.com/malashik35/KotlinAsFirst2016/blob/master/src/lesson5/task1/Parse.kt#L103-L121
Clone class 2:
https://github.com/IgorLo/KotlinAsFirst2016/blob/master/src/lesson5/task1/Parse.kt#L107-L125
https://github.com/SeveNChaK/KotlinAsFirst2016/blob/master/src/lesson5/task1/Parse.kt#L102-L119
Clone class 3:
- Дана пара отсортированных списков чисел
lst1
иlst2
. Необходимо вернуть отсортированный список, образованный объединениемlst1
иlst2
. Функциюsort
использовать нельзя. - Реализуйте тип данных, позволяющий задавать команды управления лентой вида "Влево на определённое число шагов", "Вправо на определённое число шагов", "Запись". Реализуйте функцию, которая принимает на вход список команд и начальную позицию и возвращает список позиций, на которых происходила запись.
- Дан список чисел. Необходимо посчитать число чётных и нечётных чисел в этом списке.
- Дан список чисел и функция
f :: Int -> Int -> Int
. Необходимо найти такую пару чисел(a,b)
в списке, чтоf a b
максимально. - Дан список чисел, число
n
и функцияf :: Int -> Int -> Int
. Необходимо найти любую такую пару чисел(a,b)
в списке, чтоf a b
равноn
. - Даны два списка чисел,
a
иb
. Нужно посчитать произведение всех попарных сумм элементов изa
иb
. - Дано число
n
и функцияf :: a -> a
. Необходимо вернуть
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
inline class AppendScope(val appendable: Appendable) { | |
inline fun indent(indent: Int = 4, body: IndentScope.() -> Unit) { | |
IndentScope(indent).body() | |
} | |
} | |
inline fun AppendScope.appendln(value: CharSequence) = appendable.appendln(value) | |
inline class IndentScope(val indent: Int = 4) { | |
inline fun AppendScope.appendln(value: CharSequence) = appendable.append(" ".repeat(indent)).appendln(value) |
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
// sum type (typical Kotlin implementation) | |
sealed class Expr | |
data class Var(val name: String): Expr() | |
data class Constant(val value: Int): Expr() | |
object Empty: Expr() | |
// union type (hypothetical) | |
data class Var(val name: String) | |
data class Constant(val value: Int) | |
object Empty |
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
class Covariant<out T> | |
class Contravariant<in T> | |
class Invariant<T> | |
infix fun KType.equiv(that: KType) = isSubtypeOf(that) && isSupertypeOf(that) | |
@Test | |
fun mooEver() { | |
/* Covariant<*> =:= Covariant<Any?> =:= Covariant<out Any?> */ | |
/* Covariant<in Nothing> is an illegal type */ |
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
newtype PSet a = PSet{ contains :: (a -> Bool) } | |
newtype PSet2 a = PSet2{ contains2 :: (a -> Bool) } | |
newtype PSet3 a = PSet3{ contains3 :: (a -> Bool) } | |
-- сложение множеств | |
instance Monoid (PSet a) where | |
mempty = PSet (\a -> False) | |
mappend (PSet f1) (PSet f2) = PSet (\a -> (f1 a) || (f2 a)) | |
-- пересечение множеств |
NewerOlder