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
// >= 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 |
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
module FastExpMod | |
( | |
expmod | |
, pow | |
, mul | |
) where | |
lastDigit :: Integer -> Integer -> Integer | |
lastDigit a b = pow a b 10 |
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 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) |
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
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]) { |
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
# encoding: utf-8 | |
# посчитать количество слов в предложении | |
# входные данные: str | |
# выходные данные: int | |
SPECIAL_CHARS = ['-'] | |
def is_alphabetic(char: str) -> bool: | |
return char.isalpha() or char in SPECIAL_CHARS |
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
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")) { |
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
""" | |
предполагаем что в последовательности нечётное число элементов для простоты | |
предполагаем что число элементов делится на 5 для простоты | |
""" | |
def pick_pivot(l): | |
""" | |
Выбираем хорошй pivot в списке чисел l | |
Этот алгоритм выполняется за время O(n). |
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 datastructures; | |
import java.util.Comparator; | |
public class BinomailHeap<K extends Comparable> { | |
private Node<K> head; | |
private int size; | |
private Comparator<K> comparator; |
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
public class ArrayAlgorithm { | |
private static long iterations; | |
public static long sort(int[] array) { | |
iterations = 0; | |
quickSort(array, 0, array.length - 1); | |
return iterations; | |
} |
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
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; |