http://www.pixelstech.net/article/1316620955-Permutation-algorithm-with-JavaScript
In secondary school, we have learned permutation. Basically, for n numbers, the number of permutations for these n numbers can be calculated to n! which is called 'n factorial'. But to display all the permutations on the screen, we need to use a recursive function. The problem is how to write this function.
Next I write a program to display the permutations for n numbers with JavaScript. First, we need to understand that from these n numbers, we can first take any one number from it, and the (n-1) numbers remaining has the similar property as the n numbers, we need to find the permutations for the (n-1) numbers, and from these (n-1) numbers, we take any one of them and there are (n-2) numbers which we need to find the permutations of them. So the whole process will stop when there is only one number left, we will can display the permutations. It is a recursive process. The code can be shown below:
среда, 22 июня 2016 г.
create all permutation of a string
http://www.thatjsdude.com/interview/js1.html#permutation
Question: How would you create all permutation of a string?
Answer: This could be a tough one based on you level of knowledge about algorithm.
function permutations(str){
var arr = str.split(''),
len = arr.length,
perms = [],
rest,
picked,
restPerms,
next;
if (len == 0)
return [str];
for (var i=0; i<len; i++)
{
rest = Object.create(arr);
picked = rest.splice(i, 1);
restPerms = permutations(rest.join(''));
for (var j=0, jLen = restPerms.length; j< jLen; j++)
{
next = picked.concat(restPerms[j]);
perms.push(next.join(''));
}
}
return perms;
}
Explanation:
- Idea: Idea is very simple. We will convert the string to an array. from the array we will pick one character and then permute rest of it. After getting the permutation of the rest of the characters, we will concatenate each of them with the character we have picked.
- step-1 First copy original array to avoid changing it while picking elements
- step-2 Use splice to removed element from the copied array. We copied the array because splice will remove the item from the array. We will need the picked item in the next iteration.
- step-3 [1,2,3,4].splice(2,1) will return [3] and remaining array = [1,2,4]
- step-4 Use recursive method to get the permutation of the rest of the elements by passing array as string
- step-5 Finally, concat like a+permute(bc) for each
умножение матрицы на число
Определение.
Произведением матрицы A на число k называется матрица B = k · A того же размера, полученная из исходной умножением на заданное число всех ее элементов:
bi,j = k · ai,j
Свойства умножения матрицы на число
- 1 · A = A
- 0 · A = Θ, где Θ - нулевая матрица
- k · (A + B) = k · A + k · B
- (k + n) · A = k · A + n · A
- (k · n) · A = k · (n · A)
отсюда...
сложение и вычитание матриц
Складывать и вычитать можно матрицы одного размера в результате получается матрица того же размера.
Определение.
Сложение матриц (сумма матриц) A + B есть операция вычисления матрицы C, все элементы которой равны попарной сумме всех соответствующих элементов матриц A и B, то есть каждый элемент матрицы C равен:
сij = aij + bij
Определение.
Вычитание матриц (разность матриц) A - B есть операция вычисления матрицы C, все элементы которой равны попарной разности всех соответствующих элементов матриц A и B, то есть каждый элемент матрицы C равен:
сij = aij - bij
Свойства сложения и вычитания матриц
- Ассоциативность: (A + B) + C = A + (B + C)
- A + Θ = Θ + A = A, где Θ - нулевая матрица
- A - A = Θ
- Коммутативность: A + B = B + A
отсюда...
воскресенье, 19 июня 2016 г.
пятница, 17 июня 2016 г.
переустановить Windows 10
сейчас у меня на ноутбуке Windows 10, бесплатно установленная с 8.1...в настоящее время -- присутствуют некоторые проблемы, например, не работает Пуск...я хочу снова переустановить Windows 10...как мне это сделать?..
1) Создать загрузочный носитель той же редакции, что и Ваша 10-ка:
2) Выполнить чистую установку с созданного носителя:
четверг, 16 июня 2016 г.
вращение векторов (заметка)
эта заметка — личная...
лежит пока вот тут:
palaeo.spb.ru/algorithms/vector_rotation/
лежит пока вот тут:
palaeo.spb.ru/algorithms/vector_rotation/
Подписаться на:
Сообщения (Atom)

