text: var Algorithm=(function(){if(!Algorithm){return{REVISION:"1",verison:"1.0",linearSearch:function(c,a){var d=a.length,b=0;a[d]=c;while(a[b]!==c){b++}if(b<d){return b}else{return -1}},binarySearch:function(e,a){var d=0,c=a.length,b;while(d<c){b=Math.floor((d+c)/2);if(e<=a[b]){c=b}else{d=b+1}}if(a[d]===e){return d}else{return -1}},substringSearch:function(c,e){var b,a,f=c.length,d=e.length-f+1;for(b=0;b<d;b++){a=0;while(a<f&&c.charAt(a)===e.charAt(b+a)){a++}if(a===f){return b}}return -1},bubbleSort:function(a){var e=a.length;for(var d=0;d<e-1;d++){for(var b=0;b<e-1-d;b++){if(a[b+1]<a[b]){var c=a[b+1];a[b+1]=a[b];a[b]=c}}}return a},selectionSort:function(a){var f=a.length;for(var e=0;e<f-1;e++){var d=e;for(var b=e+1;b<f;b++){if(a[b]<a[d]){d=b}}var c=a[d];a[d]=a[e];a[e]=c}return a},insertionSort:function(a){var e=a.length;for(var d=0;d<e;d++){var b=a[d],c=d-1;while(c>=0&&a[c]>b){a[c+1]=a[c];c--}a[c+1]=b}return a},shellSort:function(a){var f=a.length,e=Math.floor(f/2);while(e>0){for(var c=0;c<f;c++){var b=c,d=a[c];while(b>=e&&a[b-e]>d){a[b]=a[b-e];b-=e}a[b]=d}e=(e==2)?1:Math.floor(e*5/11)}return a},simpleCountingSort:function(a){var f=a.length,b=[],e=[];for(var d=0;d<f;d++){b[d]=0}for(var d=0;d<f-1;d++){for(var c=d+1;c<f;c++){if(a[d]<a[c]){b[c]++}else{b[d]++}}}for(var d=0;d<f;d++){e[b[d]]=a[d]}return e},combSort:function(a){var f=a.length,e=f;function d(g){g/=1.3;if(g==9||g==10){g=11}if(g<1){return 1}return g}do{swapped=false;e=d(e);for(var c=0;c<f-e;++c){if(a[c]>a[c+e]){swapped=true;var b=a[c+e];a[c+e]=a[c];a[c]=b}}}while(e>1||swapped);return a},mergeSort:function(a){function b(p,n,q,f){var o=new Array(f+1-n),m,l,g=q+1,e,m=n,l=0;while(m<=q&&g<=f){if(p[m]<=p[g]){o[l]=p[m];m++}else{o[l]=p[g];g++}l++}if(m>q){for(e=g;e<=f;e++){o[l]=p[e];l++}}else{for(e=m;e<=q;e++){o[l]=p[e];l++}}for(e=0;e<=f-n;e++){p[e+n]=o[e]}return p}function c(f,e,h){if(e<h){var g=Math.floor((e+h)/2);c(f,e,g);c(f,g+1,h);b(f,e,g,h)}}var d=a.length;c(a,0,d-1);return a},heapSort:function(a){if(a.length==0){return[]}var f=a.length,e=Math.floor(f/2),c,b,d;while(true){if(e>0){d=a[--e]}else{f--;if(f==0){return a}d=a[f];a[f]=a[0]}c=e;b=c*2+1;while(b<f){if(b+1<f&&a[b+1]>a[b]){b++}if(a[b]>d){a[c]=a[b];c=b;b=c*2+1}else{break}}a[c]=d}},quickSort:function(d){if(d.length==0){return[]}var e=[],c=[],g=d[0];for(var f=1;f<d.length;f++){if(d[f]<g){e[e.length]=d[f]}else{c[c.length]=d[f]}}return Algorithm.quickSort(e).concat(g,Algorithm.quickSort(c))},cocktailSort:function(a){var e=0,c=a.length-1,f=true,d;while(e<c&&f){f=false;for(var b=e;b<c;b++){if(a[b]>a[b+1]){d=a[b];a[b]=a[b+1];a[b+1]=d;f=true}}c--;if(f){f=false;for(var b=c;b>e;b--){if(a[b]<a[b-1]){d=a[b];a[b]=a[b-1];a[b-1]=d;f=true}}}e++}return a},gnomeSort:function(a){var e=a.length,d=1,b=2;while(d<e){if(a[d-1]<a[d]){d=b;b++}else{var c=a[d-1];a[d-1]=a[d];a[d]=c;d--;if(d==0){d=b;b++}}}return a},naturalSort:function(e){var g=e.map(f),d=g.sort(a);return d.map(function(i){return i.item});function f(i){return new h(i)}function h(n){var j=0,p=0,o=[],m=false;this.item=n;var k=n;this.key=k;this.count=function(){return o.length};this.part=function(q){while(o.length<=q&&!m){l()}return q<o.length?o[q]:null};function l(){if(j<k.length){while(++j){var s=b(k.charAt(j-1)),u=k.charAt(j),t=j===k.length,q=t||c(s,b(u));if(q){var r=k.slice(p,j);o.push(new i(r,s));p=j;break}}}else{m=true}}function i(r,q){this.isNumber=q;this.value=q?Number(r):r}}function a(j,p){var m=0;do{var o=j.part(m),l=p.part(m);if(null!==o&&null!==l){if(c(o.isNumber,l.isNumber)){return o.isNumber?-1:1}else{var k=n(o.value,l.value);if(k!=0){return k}}}else{return n(j.count(),p.count())}}while(++m);function n(q,i){return q<i?-1:q>i?1:0}}function c(j,i){return j?!i:i}function b(j){var k=i(j);return k>=i("0")&&k<=i("9");function i(l){return l.charCodeAt(0)}}},testUnique:function(a){var d=a.length;for(var c=0;c<d-1;c++){for(var b=c+1;b<d;b++){if(a[c]===a[b]){return false}}}return true},unique:function(a){var f=a.length,b=0,e=[];for(var d=0;d<f;d++){var c=0;while(c<b&&e[c]!==a[d]){c++}if(c==b){e[b++]=a[d]}}return e},getUniqueElems:function(a){var f=a.length,e=[];for(var d=1,b=0,c;d<f+1;d++){if(a[d-1]===a[d]){c=a[d-1]}if(a[d-1]!==c){e[b++]=a[d-1]}}return e},getDublsSortArr:function(a){var e=a.length,d=[];for(var c=1,b=0;c<e;c++){if(a[c-1]===a[c]){d[b++]=a[c-1]}}return Algorithm.unique(d)},mergeArray:function(a,h){var f=a.length,g=h.length,e=[];for(var d=0,c=0,b=0;b<f+g;b++){if(d==f){e[b]=h[c++];continue}if(c==g){e[b]=a[d++];continue}e[b]=(a[d]<h[c])?a[d++]:h[c++]}return e},multiMergeArray:function(b,a){var c=a.length;if(b==c-2){return Algorithm.mergeArray(a[c-2],a[c-1])}else{return Algorithm.mergeArray(a[b],Algorithm.multiMergeArray(b+1,a))}},intersecArrays:function(d,b){var f=d.length,e=b.length,o=0,a=[];for(var l=0;l<f;l++){var h=0,g=0;while(b[h]!==d[l]&&h<e){h++}while(a[g]!==d[l]&&g<o){g++}if(h!=e&&g==o){a[o++]=d[l]}}return a},multiIntersecArrays:function(b,a){var c=a.length;if(b==c-2){return Algorithm.intersecArrays(a[c-2],a[c-1])}else{return Algorithm.intersecArrays(a[b],Algorithm.multiIntersecArrays(b+1,a))}},intersecSortArr:function(e,d){var o=e.length,l=d.length,c=[],g=1,f=1,h=0,q=0,p=0;for(var j=1,r=e[0];j<o;j++){if(e[j]!==r){e[g++]=e[j];r=e[j]}}for(var j=1,r=d[0];j<l;j++){if(d[j]!==r){d[f++]=d[j];r=d[j]}}while(q<g&&p<f){if(e[q]<d[p]){++q}else{if(e[q]>d[p]){++p}else{С[h++]=e[q++]}}}return c},multiIntersecSortArr:function(b,a){var c=a.length;if(b==c-2){return Algorithm.intersecSortArr(a[c-2],a[c-1])}else{return Algorithm.intersecSortArr(a[b],Algorithm.multiIntersecSortArr(b+1,a))}},diffArrays:function(d,b){var l=d.length,h=b.length,m=0,a=[];for(var g=0;g<l;g++){var f=0,e=0;while(b[f]!==d[g]&&f<h){f++}while(a[e]!==d[g]&&e<m){e++}if(f==h&&e==m){a[m++]=d[g]}}return a},multiDiffArrays:function(b,a){var c=a.length;if(b==c-2){return Algorithm.diffArrays(a[c-2],a[c-1])}else{return Algorithm.diffArrays(a[b],Algorithm.multiDiffArrays(b+1,a))}},diffSortArr:function(e,d){var b=Algorithm.intersecSortArr(e,d),j=e.length,h=b.length;for(var g=0,f=0,m=0,l=0;g<j+h;g++){if(e[m]===b[l]){++m;++l}else{e[f]=e[g];f++;m++}}e.length=f;return e},multiDiffSortArr:function(b,a){var c=a.length;if(b==c-2){return Algorithm.diffSortArr(a[c-2],a[c-1])}else{return Algorithm.diffSortArr(a[b],Algorithm.multiDiffSortArr(b+1,a))}},symmDiffSortArr:function(c,b){var g=c.length,h=b.length;for(var f=1,e=1,d=c[0];f<g;f++){if(c[f]!==d){c[e++]=c[f];d=c[f]}}c.length=e;for(var f=1,e=1,d=b[0];f<h;f++){if(b[f]!==d){b[e++]=b[f];d=b[f]}}b.length=e;var g=c.length,h=b.length,a=[];for(var f=0,e=0,d=0;d<g+h;d++){if(f==g){a[d]=b[e++];continue}if(e==h){a[d]=c[f++];continue}a[d]=(c[f]<b[e])?c[f++]:b[e++]}var g=a.length;for(var f=1,e=0,l;f<g+1;f++){if(a[f-1]===a[f]){l=a[f-1]}if(a[f-1]!==l){a[e++]=a[f-1]}}a.length=e;return a},multiSymmDiffSortArr:function(b,a){var c=a.length;if(b==c-2){return Algorithm.symmDiffSortArr(a[c-2],a[c-1])}else{return Algorithm.symmDiffSortArr(a[b],Algorithm.multiSymmDiffSortArr(b+1,a))}},unionSortArr:function(a,h){var f=a.length,g=h.length,e=[];for(var d=0,c=0,b=0;b<f+g;b++){if(d==f){e[b]=h[c++];continue}if(c==g){e[b]=a[d++];continue}e[b]=(a[d]<h[c])?a[d++]:h[c++]}for(var d=1,c=e[0],b=1;d<f+g;d++){if(e[d]!==c){e[b++]=e[d];c=e[d]}}e.length=b;return e},multiUnionSortArr:function(b,a){var c=a.length;if(b==c-2){return Algorithm.unionSortArr(a[c-2],a[c-1])}else{return Algorithm.unionSortArr(a[b],Algorithm.multiUnionSortArr(b+1,a))}},GCD:function(b){var e=b.length,a=Math.abs(b[0]);for(var c=1;c<e;c++){var d=Math.abs(b[c]);while(a&&d){a>d?a%=d:d%=a}a+=d}return a},LCM:function(e){var j=e.length,f=Math.abs(e[0]);for(var g=1;g<j;g++){var d=Math.abs(e[g]),h=f;while(f&&d){f>d?f%=d:d%=f}f=Math.abs(h*e[g])/(f+d)}return f},NOD:function(a){return Algorithm.GCD(a)},NOK:function(a){return Algorithm.LCM(a)},transMatrix:function(b){var a=b.length,f=b[0].length,c=[];for(var e=0;e<f;e++){c[e]=[];for(var d=0;d<a;d++){c[e][d]=b[d][e]}}return c},sumMatrix:function(b,g){var a=b.length,f=b[0].length,e=[];for(var d=0;d<a;d++){e[d]=[];for(var c=0;c<f;c++){e[d][c]=b[d][c]+g[d][c]}}return e},multMatrixNumber:function(d,c){var b=c.length,h=c[0].length,g=[];for(var f=0;f<b;f++){g[f]=[];for(var e=0;e<h;e++){g[f][e]=d*c[f][e]}}return g},multiplyMatrix:function(g,d){var f=g.length,c=g[0].length,e=d.length,a=d[0].length,b=[];if(c!=e){return false}for(var m=0;m<f;m++){b[m]=[]}for(var h=0;h<a;h++){for(var m=0;m<f;m++){var n=0;for(var l=0;l<e;l++){n+=g[m][l]*d[l][h]}b[m][h]=n}}return b},matrixPow:function(b,a){if(b==1){return a}else{return Algorithm.multiplyMatrix(a,Algorithm.matrixPow(b-1,a))}},determinantMatrix:function(b){var l=b.length,a=[],g=1,p=0;for(var e=0;e<l;++e){a[e]=[];for(var d=0;d<l;++d){a[e][d]=b[e][d]}}for(var e=0;e<l-1;++e){var f=e,h=Math.abs(a[e][e]);for(var d=e+1;d<l;++d){var o=Math.abs(a[d][e]);if(o>h){f=d;h=o}}if(f>e){var q=a[e];a[e]=a[f];a[f]=q;++p}else{if(h==0){return h}}var n=a[e][e];for(var d=e+1;d<l;++d){var m=a[d][e];a[d][e]=0;for(var c=e+1;c<l;++c){a[d][c]=(a[d][c]*n-a[e][c]*m)/g}}g=n}if(p%2){return -a[l-1][l-1]}else{return a[l-1][l-1]}},matrixRank:function(g){var j=g.length,h=g[0].length,l=(j<h?j:h),e=1,o=0;while(e<=l){var f=[];for(var p=0;p<e;p++){f[p]=[]}for(var u=0;u<j-e+1;u++){for(var t=0;t<h-e+1;t++){for(var s=0;s<e;s++){for(var q=0;q<e;q++){f[s][q]=g[u+s][t+q]}}if(Algorithm.determinantMatrix(f)!=0){o=e}}}e++}return o},adjugateMatrix:function(b){var h=b.length,k=[];for(var g=0;g<h;g++){k[g]=[];for(var f=0;f<h;f++){var a=[],d=((g+f)%2==0)?1:-1;for(var e=0;e<f;e++){a[e]=[];for(var c=0;c<g;c++){a[e][c]=b[e][c]}for(var c=g+1;c<h;c++){a[e][c-1]=b[e][c]}}for(var e=f+1;e<h;e++){a[e-1]=[];for(var c=0;c<g;c++){a[e-1][c]=b[e][c]}for(var c=g+1;c<h;c++){a[e-1][c-1]=b[e][c]}}k[g][f]=d*Algorithm.determinantMatrix(a)}}return k},inverseMatrix:function(a){var d=Algorithm.determinantMatrix(a);if(d==0){return false}var e=a.length,a=Algorithm.adjugateMatrix(a);for(var c=0;c<e;c++){for(var b=0;b<e;b++){a[c][b]/=d}}return a},getRandomArbitary:function(b,a){return Math.random()*(a-b)+b},getRandomInt:function(b,a){return Math.floor(Math.random()*(a-b+1))+b},getFibonahhiNumber:function(b){var a;a=(Math.pow(((1+Math.sqrt(5))/2),b)-Math.pow(((1-Math.sqrt(5))/2),b))/Math.sqrt(5);return a},getFibonahhiPosition:function(k){var e,f,d,j,h;if(k<3&&k>-3){e=k}else{f=1;d=1;j=f+d;h=1;if(k<0){h=-1}k=Math.abs(k);for(var g=2;j<k;g++){j=f+d;f=d;d=j}if(j>k){e=false}else{e=g*h}}return e}}}}());