Skip to content

Instantly share code, notes, and snippets.

View artemohanjanyan's full-sized avatar
🎯
Focusing

Artem Ohanjanyan artemohanjanyan

🎯
Focusing
View GitHub Profile
maze :: Integer -> Integer -> Integer
maze x y
| abs x > 10 || abs y > 10 = 0
| x == 0 && y == 0 = 2
| abs x == 9 && abs y == 9 = 1
| abs x == 10 || abs y == 10 = 1
| x == y = 3
| abs x == abs y = 4
| x < 0 && x > (-9) && y == 0 = 4
| x > 0 && x < 9 && y == 0 = 3
object Poly {
val show: Any => String = {
case x: Int => s"Int($x)"
case x: Long => s"Long($x)"
case x: String => s"String($x)"
case _ => ???
}
def show1(x: Int): String = s"Int($x)"
def show1(x: Long): String = s"Long($x)"
@artemohanjanyan
artemohanjanyan / BooleanFunction.idr
Created May 24, 2021 10:56
Function which prints truth table for any boolean function in Idris
first : (a -> b) -> (a, c) -> (b, c)
first f (x, y) = (f x, y)
interface BooleanFunction a where
makeTable : a -> List (List Bool, Bool)
BooleanFunction Bool where
makeTable result = [([], result)]
BooleanFunction a => BooleanFunction (Bool -> a) where
import Control.Monad (foldM_)
import Data.List (foldl')
import System.IO
import qualified System.Random as R
data Treap =
Node (Int, Int) Treap Treap |
Null
instance Show Treap where
module EvenOdd
import Data.Fin
%access public export
%default total
data Even : (n: Nat) -> Type where
ZEven : Even Z
SsEven : (n: Nat) -> Even n -> Even (S (S n))
@artemohanjanyan
artemohanjanyan / Existential.idr
Created January 11, 2019 19:21
Existential types explained in Idris code
module Existential
%access public export
StackInterface : Type -> Type
StackInterface a = ( a
, Integer -> a -> a
, a -> (a, Integer)
)
-- | Stores information for printing expressions in their original form.
data FormattedExprExt
type instance XExprProcCall FormattedExprExt _ _ = NoExt
type instance XExprLit FormattedExprExt _ _ = Selection
-- | Space between the brackets and nested expression.
type instance XXExpr FormattedExprExt cmd components =
ExprInBrackets FormattedBracket (Expr FormattedExprExt cmd components)
-- | Information about the space between procedure and its arguments and between
@artemohanjanyan
artemohanjanyan / java.md
Last active March 19, 2018 11:28
Технологии Java, группа M3236

Бонусы

  • Красивая поддержка случая fromElement > toElement в subSet
  • Красивая с точки зрения ООП реализация NavigableSet
  • Поддержка protected интерфейсов (или классов) в задании Implementor

Календарь

HW Deadline Hard Deadline
1 14.02.2018 15.03.2018
2 22.02.2018 22.03.2018
@artemohanjanyan
artemohanjanyan / zip.java
Last active August 29, 2016 10:52
Zip for SolidList
/**
* Returns a new stream that contains items that has been received by sequentially combining items of the streams into pairs
* and then applying given function to each pair of items.
*
* @param with a {@link Stream} to zip current stream with.
* @param func a function that takes an item of the current stream and an item of another stream
* and returns a corresponding value for the new stream.
* @param <S> a type of a stream to zip current stream with.
* @param <R> a type of items new stream returns.
* @return a new stream that contains items that has been received by sequentially combining items of the streams into pairs