>>> fruits = ['бананы', 'яблоки', 'груши']
>>> for _ in range(10):
print(random.choices(fruits, weights=[0.8, 0.1, 0.1])[0])
бананы
бананы
бананы
груши
бананы
бананы
бананы
бананы
яблоки
бананы
var matrixes = [
[
[3, 2, 1],
[1, 2, 3],
[3, 1, 3]
], // Должен выводится 3
[
[3, 2, 1],
[1, 2, 3],
[3, 2, 1]
], // Должен выводится 0
[
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]
], // Должен выводится 4
[
[2, 4],
[4, 2]
] // Должен выводится 0
];
matrixes.forEach( matrix => {
console.log("------------------------");
console.table(matrix);
console.log(calc(matrix));
});
function calc(matrix){
let template = matrix[0];
let result = matrix.reduce( (acc1, items, index1) => {
if(index1===0) return acc1;
template = template.reverse();
acc1 += items.reduce( (acc2, item, index2) => {
acc2 += Math.abs(template[index2]-item);
return acc2;
},0);
return acc1;
},0);
return result;
}
string1 = 'abcdefghij'
string2 = '123cdie456'
print(string1.translate({ord(c): '' for c in string2}))
import numpy as np
from numba import njit
# С использованием numpy
def max_divisors_v1(n):
divs = np.ones(n + 1, np.uint8)
for step in range(2, n + 1):
divs[step::step] += 1
divs[0] = 0
num = divs.argmax()
return num, divs[num]
# Без numpy, чистый Python
def max_divisors_v2(n):
divs = [1] * (n + 1)
for step in range(2, n + 1):
for index in range(step, n + 1, step):
divs[index] += 1
divs[0] = 0
cnt = max(divs)
num = divs.index(cnt)
return num, cnt
# JIT-компиляция с декоратором @njit
max_divisors_v3 = njit(max_divisors_v2)
paw(2, 5) = 2 * paw(2, 4)
2 * paw(2, 4) --> paw(2, 4) = 2 * paw(2, 3)
2 * (2 * paw(2, 3)) --> paw(2, 3) = 2 * paw(2, 2)
2 * (2 * (2 * paw(2, 2))) --> paw(2, 2) = 2 * paw(2, 1)
2 * (2 * (2 * (2 * paw(2, 1)))) --> paw(2 ,1) = 2
2 * (2 * (2 * (2 * 2)))
let one = ['one', 'two', 'three', 'four', 'five'];
let two = ['a', 'b', 'five', 'c', 'one'];
const [long, short] = one.length > two.length ? [one,two] : [two,one];
short.sort();
const shortLength = short.length;
const binSearch = needle => {
let start = 0, finish = shortLength - 1;
while (start <= finish) {
const center = Math.floor((start + finish) / 2);
if (short[center] < needle) start = center + 1;
else if (short[center] > needle) finish = center - 1;
else return true;
}
return false;
}
const result = [];
for (let i = 0, length = long.length; i < length; i++)
if (binSearch(long[i])) result.push(long[i]);
result // ["five","one"]
my_list = ['apple', 'banana', 'grapes', 'pear']
for c, value in enumerate(my_list, 1):
print(c, value)
# Output:
# 1 apple
# 2 banana
# 3 grapes
# 4 pear
const newArr = arr.map((n, i) => n.repeat(i + 1));
const newArr = arr.map((n, i) => Array(i + 1).fill(n).join(''));
const newArr = arr.map((n, i) => Array(i + 2).join(n));
const newArr = [];
for (let i = 0; i < arr.length; i++) {
let str = '';
for (let j = 0; j <= i; j++) {
str += arr[i];
}
newArr.push(str);
}
const newArr = [];
for (const n of arr) {
let str = '';
while ((str = str.concat(n)).length <= newArr.length) ;
newArr[newArr.length] = str;
}
A | B | ¬(¬(A∧B) ∧ ¬(¬A∧¬B))
0 | 0 | 1
0 | 1 | 0
1 | 0 | 0
1 | 1 | 1