function floorCount(start, max) {
let result = 0;
let prevStart = -1;
while (start > 0) {
for (let x = start; x <= max && x !== prevStart; x = x % 2 ? 2 * x : 2 * x - 1) {
result++;
}
prevStart = start;
start = start < 2 ? 0 : start % 2 ? (start + 1) / 2 : start / 2;
}
return result;
}
function bankomat(sum, coins, maxCC) {
const full = coins.reduce((sum, c) => sum + c * maxCC, 0);
if (full < sum) return -1;
const dp = Array.from({length: sum + 1}, () => ({
count: full + 1,
coins: {},
}));
coins.sort((a, b) => a - b);
dp[0].count = 0;
for (let i = 1; i <= sum; ++i) {
const item = dp[i];
let optCoin = 0;
for (let j = 0; j < coins.length; ++j) {
const coin = coins[j];
if (coin > i) break;
const prev = dp[i - coin];
if (item.count > prev.count + 1 && (prev.coins[coin] || 0) < maxCC) {
item.count = prev.count + 1;
optCoin = coin;
}
}
if (optCoin) {
const prev = dp[i - optCoin];
item.coins = {
...prev.coins,
[optCoin]: (prev.coins[optCoin] || 0) + 1
};
}
}
if (dp[sum].count > full) {
return 0;
}
const arr = [];
Object.keys(dp[sum].coins).forEach((coin) => {
const c = dp[sum].coins[coin];
for (let i = 0; i < c; ++i) {
arr.push(Number(coin));
}
});
return arr;
}
console.log(bankomat(100, [11, 20, 30, 40, 12, 99], 2)); // [20, 40, 40]
обычно добавляют, что это же означает, что то, что событие B произошло не даёт никакой информации относительно события A
type FuncSetNameParams = ['employers', {company: string}] | ['employees', {fio: string}] | ['products', {name: string}];
const setName = (...[key, item]: FuncSetNameParams): string => {
switch (key) {
case 'employers':
return item.company
case 'employees':
return item.fio
case 'products':
return item.name
}
}
const fib = (n, a = []) => {
if (n < 1) {
a[0] = 0n;
a[1] = 1n;
} else {
const m = Math.floor(n/2);
fib(m, a);
const x = a[0] * (2n * a[1] - a[0]);
const y = a[0] * a[0] + a[1] * a[1];
if (n % 2) {
a[0] = y;
a[1] = x + y;
} else {
a[0] = x;
a[1] = y;
}
}
return a;
}
const sumFib3n = (n) => {
if (n < 1) { return 0n; }
const [fn, fnp1] = fib(n); // fn = fib(n), fnp1 = fib(n+1),
const fnm1 = fnp1 - fn; // fnm1 = fib(n-1),
const sgn = n % 2 ? 1n : -1n;
const sumPow3 = (fn * fnp1 * fnp1 + sgn * fnm1 + 1n) / 2n;
return sumPow3 - 1n + fn * fn * fn + fnp1 * fnp1 * fnp1;
}
console.log(sumFib3n(Math.floor((40000000 - 2)/3)));
function getIntermediateItems(tree, result = []) {
tree?.forEach((item) => {
if (item.workControl?.includes('intermediate')) {
result.push(item);
}
getIntermediateItems(item.content, result);
});
return result;
}
const arr = getIntermediateItems(myarr);
document.getElementById("dd").prepend(JSON.stringify(arr, '', 4))