Skip to content

Instantly share code, notes, and snippets.

View belyaev-mikhail's full-sized avatar

Mikhail Belyaev belyaev-mikhail

  • SPBSTU
  • Saint-Petersburg, Russia
View GitHub Profile
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> {
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.*
  1. Даны два списка чисел. Верните список чисел, присутствующих в обоих исходных списках.

    Пример:

    mergeLists [0,1,2,3,4] [4,2,40] -> [2,4]
    mergeLists [0,1,2] [4,5] -> []
  2. Дан список чисел ts и число x. Верните список чисел, в которых присутствует хотя бы одна такая же цифра, как в x. Систему счисления считать десятичной.

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)
// 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
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 */
@belyaev-mikhail
belyaev-mikhail / 3_3
Created June 10, 2019 22:06 — forked from ChinarevaEV/3_3
3_3
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))
-- пересечение множеств
@belyaev-mikhail
belyaev-mikhail / 3_2
Created June 10, 2019 22:06 — forked from ChinarevaEV/3_2
3_2
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]
@belyaev-mikhail
belyaev-mikhail / 3_1
Created June 10, 2019 22:06 — forked from ChinarevaEV/3_1
3_1
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
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 _ [] = []