-
Даны два списка чисел. Верните список чисел, присутствующих в обоих исходных списках.
Пример:
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
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.* |
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)) | |
-- пересечение множеств |
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
data ReverseList a = RNil | RCons (ReverseList a) a | |
showAsList :: (Show a) => ReverseList a -> String | |
showAsList RNil = "" | |
showAsList (RCons RNil h) = show h | |
showAsList (RCons tl hl) = (showAsList tl) ++ ", " ++ (show hl) | |
toList :: ReverseList 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
data PeanoNumber = Zero | Succ (PeanoNumber) | Pred (PeanoNumber) deriving Show | |
isSimple :: PeanoNumber -> Bool | |
isSimple Zero = True | |
isSimple (Succ (Pred _)) = False | |
isSimple (Pred (Succ _)) = True | |
isSimple (Succ num) = isSimple num | |
isSimple (Pred num) = isSimple num |
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
my_foldr :: (a -> b -> b) -> b -> [a] -> b | |
my_foldr f x [] = x | |
my_foldr f x (h : t) = f h (my_foldr f x t) | |
my_foldl :: (b -> a -> b) -> b -> [a] -> b | |
my_foldl f x [] = x | |
my_foldl f x (h : t) = my_foldl f (f x h) t | |
my_map :: (a -> b) -> [a] -> [b] | |
my_map _ [] = [] |
NewerOlder