Skip to content

Instantly share code, notes, and snippets.

View Dimanaux's full-sized avatar

Dmitry Barskov Dimanaux

View GitHub Profile
// >= 0, <= 1_000_000
// problem suggests that string can only contain 'million'
// or less -> million can occure only once and it's the whole string
const parseInt = (string) =>
string.includes('million')
? 1000000 : parseMillion(string);
// < 1_000_000
// if we have 'thousand' word in given string,
// split on it and solve parse left, multiply it by 1000
@Dimanaux
Dimanaux / FastExpMod.hs
Last active February 5, 2019 13:12
Something is wrong...
module FastExpMod
(
expmod
, pow
, mul
) where
lastDigit :: Integer -> Integer -> Integer
lastDigit a b = pow a b 10
class Category(models.Model):
title = models.CharField(max_length=32, unique=True)
class Test(models.Model):
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
title = models.CharField(max_length=32)
description = models.TextField()
category = models.ForeignKey('Category', on_delete=models.CASCADE)
const binarySearch = (array, value) => {
const iter = (from, to) => {
let m = Math.floor((from + to) / 2);
if (value === array[m]) {
return m;
} else if (to - from > 1) {
if (value < array[m]) {
return iter(from, m);
} else if (value > array[m]) {
@Dimanaux
Dimanaux / word_count.py
Last active August 30, 2018 16:31
Write a function that takes a text and returns amount of words in the text. Write it in two styles: imperative and declarative
# encoding: utf-8
# посчитать количество слов в предложении
# входные данные: str
# выходные данные: int
SPECIAL_CHARS = ['-']
def is_alphabetic(char: str) -> bool:
return char.isalpha() or char in SPECIAL_CHARS
import java.util.LinkedList;
import java.util.List;
public class AbstractFactorySample {
public static void main(String[] args) {
String uname = System.getProperty("os.name").toLowerCase();
Application application;
if (uname.contains("windows")) {
"""
предполагаем что в последовательности нечётное число элементов для простоты
предполагаем что число элементов делится на 5 для простоты
"""
def pick_pivot(l):
"""
Выбираем хорошй pivot в списке чисел l
Этот алгоритм выполняется за время O(n).
@Dimanaux
Dimanaux / BinomailHeap.java
Last active January 25, 2022 18:38
Binomial heap java implementation
package datastructures;
import java.util.Comparator;
public class BinomailHeap<K extends Comparable> {
private Node<K> head;
private int size;
private Comparator<K> comparator;
public class ArrayAlgorithm {
private static long iterations;
public static long sort(int[] array) {
iterations = 0;
quickSort(array, 0, array.length - 1);
return iterations;
}
import java.util.ArrayList;
public class ArrayListAlgorithm {
private static long iterations;
public static long sort(ArrayList<Integer> array) {
iterations = 0;
quickSort(array, 0, array.size() - 1);
return iterations;