[math][fundamental rulese to devide nume to 11

Функция находит числа в массиве чисел, которые деляться на 11
This commit is contained in:
2024-10-13 21:22:39 +03:00
parent 20e719bebb
commit 52227188a5
3 changed files with 59 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
export function isDevided11(numbers: number[]): number[] {
const res: number[] = [];
let L = 1;
let R = numbers.length - 1
let M = 0;
while (L <= numbers.length - 1 || R >= 0) {
const L_NUM = numbers[L];
const R_NUM = numbers[R];
while (M <= numbers.length - 1) {
const M_NUM = numbers[M];
if (((L_NUM + R_NUM) - M_NUM) % 11 === 0) {
res.push(+`${L_NUM}${M_NUM}${R_NUM}`)
res.push(+`${R_NUM}${M_NUM}${L_NUM}`)
}
if (((L_NUM + M_NUM) - R_NUM) % 11 === 0) {
res.push(+`${L_NUM}${R_NUM}${M_NUM}`)
res.push(+`${M_NUM}${R_NUM}${L_NUM}`)
}
if (((R_NUM + M_NUM) - L_NUM) % 11 === 0) {
res.push(+`${R_NUM}${L_NUM}${M_NUM}`)
res.push(+`${M_NUM}${L_NUM}${R_NUM}`)
}
M++
}
L++
R--
}
return res;
};