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
@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 _ [] = []
data BinaryTree = EmptyTree
| Leaf Integer
| Node Integer BinaryTree BinaryTree
hasLeft :: BinaryTree -> Bool
hasLeft (EmptyTree) = False
hasLeft (Leaf _) = False
hasLeft (Node _ EmptyTree _) = False
hasLeft (Node _ _ _) = True
[ERROR] java.lang.IllegalStateException: Backend Internal error: Exception during code generation
Cause: Back-end (JVM) Internal error: Couldn't inline method call 'forEachOneBit' into
@org.junit.Test public final fun smokeTest(): kotlin.Unit defined in ru.spbstu.wheels.BitsTest
@Test
fun smokeTest() {
Bits(0b11001100000).forEachOneBit { bit ->
assertEquals(1, bit.popCount)
}
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <memory>
#define DECLARE_TUPLE_ACCESSORS_IN_STD(TYPE, SIZE) \
namespace std { \
template<> struct tuple_size<TYPE> { static constexpr const size_t value = SIZE; }; \
template<size_t N> struct tuple_element<N, TYPE> { using type = decltype(std::declval<TYPE>().get<N>()); }; \

1 вариант

Problem 1

Дан список и два числа: m и n (0 < m < 1000). Необходимо заменить все элементы списка с индексами, кратными m, на n.

Пример:

changeEls [1, 2, 3, 4, 5] 2 7
> [7, 2, 7, 4, 7]
module Parsers where
import Text.Parsec hiding(digit)
type Parser a = Parsec String () a
digit :: Parser Char
digit = oneOf $ ['0'..'9']
number :: Parser Integer
const asciiWords = RegExp.prototype.exec.bind(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g);
const hasUnicodeWord = RegExp.prototype.test.bind(
/[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/
);
const unicodeWords = RegExp.prototype.exec.bind(/[a-z0-9]+|[A-Z][a-z0-9]+/g);
function* iterateExec(exec: ((string: string) => string[]), string: string): IterableIterator<string> {
var res: string[];
interface Rec<A>: (Rec<A>) -> A
inline fun <A> Rec(crossinline body: (Rec<A>) -> A) = object : Rec<A> {
override fun invoke(rec: Rec<A>) = body(rec)
}
fun <T> omega(body: Rec<T>): T = Rec<T> { f -> f(f) } (body)
fun <A> y (r: ((A) -> A, A) -> A) =
omega(Rec<(A) -> A> { f -> { it -> r({ x -> f(f)(x) }, it) } })