-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMath.js
115 lines (91 loc) · 2.1 KB
/
Math.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
function math() {}
math.prototype.operacao = function (a, b, op) {
if(op == "+"){
return a+b;
}
else if(op == "-"){
return a-b;
}
else if(op == "*"){
return a*b;
}
else if(op == "/"){
if(b == 0)
return null;
else{
return a/b;
}
}
else{
return null;
}
};
math.prototype.intToBin = function (number) {
return (number >>> 0).toString(2);
};
math.prototype.arranjoSimples = function(n1, n2) {
var fatn1 = 1;
var fatn2 = 1;
var aux = n1 - n2;
for(i = 1; i < n1; i++)
fatn1 += fatn1 * i;
for(i = 1; i < aux; i++)
fatn2 += fatn2 * i;
var fatt = fatn1/fatn2;
return fatt;
};
math.prototype.primo = function(num){
var primo = 1;
if(num === 0){
console.log('Entre com um número diferente de 0');
return false;
}
while(num !== 0){
for(var i=2 ; i<num ; i++) {
if(num % i === 0) {
primo = 0;
console.log('Não é primo');
return false;
}
}
if(num == 2) {
primo = 0;
console.log('O número não é primo');
return false;
}
if(primo === 1 || num === 1)
console.log('É primo!');
return true;
}
};
math.prototype.permutacao = function(texto){
var arrayTexto = texto.split(";")
console.log(arrayTexto.length);
var calcPerm = new math();
return calcPerm.fatorial(arrayTexto.length);
};
math.prototype.function fatorial(n){
var i = 1;
var fat = 1;
while( i <= n ){
fat = fat * i;
i += 1;
}
return fat;
};
math.prototype.function CombineElements(collection, elementCount) {
var combinations = GenerateCombinations(collection.length, elementCount);
var res = [];
for(i = 0; i < combinations.length; i++) {
bitmapIndex = combinations[i].toString(2).split("").reverse().join("");
console.debug(i + ':' + bitmapIndex);
var arItem = '';
for(j = 0; j < bitmapIndex.length + 1; j++)
{
if (bitmapIndex.substring(j,j+1) == '1')
arItem += collection[j];
}
res.push(arItem);
}
return res;
}