Skip to content

Instantly share code, notes, and snippets.

View KolosovAO's full-sized avatar

Aleksei Kolosov KolosovAO

  • JettyCloud
  • Tbilisi
View GitHub Profile
// n(x + y) = xy
// xy - ny = nx
// y(x - n) = nx
// y = nx/(x - n)
function solve(n) {
let count = 1; // every equation will have solution when x === 2n and y === 2n
for (let x=n+1; x<2*n; x++) {
if ((n * x) % (x - n) === 0) {
diffrence: 

get HTMLElement from VNode:
    vn.el (domvm) | vn.$el (vue) 
get, set refs:
    set: vn._ref (domvm) | vn.$ref (vue)
    get: view.refs.REF_NAME (domvm) | view.$refs.REF_NAME (vue)
key:
    vn._key.KEY_NAME (domvm)
@KolosovAO
KolosovAO / task84.md
Last active April 11, 2018 09:00
task84
const fact = n => n > 1 ? n * fact(n - 1) : 1;

function mutationsCount(word) {
    const len = word.length;
    let mutationsCount = fact(len); //init count, if there is no repeating letters

    // find all repeating letters
    const lettersCount = [...word].reduce((acc, item) => {
 acc[item] = (acc[item] | 0) + 1;
/*
    sum of all numbers from 1 to n:
    n(n+1)/2 = k
    n(n+1) = 2k
    n^2 + n - 2k = 0
    n = (-1 +/- (1 + 8k)^.5) / 2
*/

function solve(k) {
function solve(width, height) {
    const [big, small] = width > height ? [width, height] : [height, width];
    // largest possible side of square is small part
    // ***** => *
    if (big >= small * 3) {
        return small;
    }
    // if it can't use small part as side, try to use big/3 part, it make sense when small*2 <= big < small*3
 // ******
const solve = (function() {
    // init values
    const memory = {1: 1, 2: 2, 3: 4};
    return function count(n) {
        if (memory[n]) {
            return memory[n];
        }
        /*
 total possible positions is 2^n
CNK_MAX_VALUE = 2**64
K_N_MAX_VALUE = 2**32

def binom(n, k):
	if n > K_N_MAX_VALUE or k > K_N_MAX_VALUE:
		raise Exception('n or k more than max value')
	greater = n - k if n - k > k else k
	cnk = 1
	# from greater to n, larger factorial shrinks
function solve(n, m) {
    // when m = 1, every employee have single key
    if (m === 1) {
        return 1;
    }
    // when m = 2 every employee have (n - 1) key
    // when m = n, every employee have 1 key
    if (m === 2 || m === n) {
 return n;
function solve(m, n, a, b, occupied) {
    // all possible squares
    let total = (m - a + 1) * (n - b + 1);
    // init array[m][n] with all unchecked items
    const checked = Array.from({length: m}, _ => Array.from({length: n}, __ => false));    
    
    occupied.forEach(([x, y]) => {
        // array begin from zero
        x = x - 1;
function solve(N, A, B, C) {
    let min = Infinity;
    const steps = {};

    const findPaths = (sum, index) => {
        if (steps[index] === undefined) {
            steps[index] = sum;
        } else {
 if (sum &gt;= steps[index]) { // if better path already exist, cancel next recursion