Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getperm(tab){
- var t = perm(tab);
- for(var i=0;i<t.length;i++){
- console.log(t[i])
- }
- }
- function perm(tab){
- var res = [];
- if( tab.length==1 ){
- res.push(tab);
- return res;
- }
- var uniqs = get_uniqs(tab), i,j;
- for(i=0;i<uniqs.length;i++){
- var tab2 = get_tab_except(tab, uniqs[i]);
- var tab3 = perm(tab2);
- for(j=0;j<tab3.length;j++){
- tab3[j].unshift(uniqs[i])
- res.push(tab3[j]);
- }
- }
- return res;
- }
- function get_uniqs(t){
- var res = [];
- res.push(t[0]);
- for(var i=1;i<t.length;i++){
- if( !res.includes(t[i]) ){
- res.push(t[i]);
- }
- }
- return res;
- }
- function get_tab_except(t, e){
- var res = [], i=0;
- while( t[i]!=e ){
- res.push(t[i]);
- i++;
- }i++;
- while( i<t.length ){
- res.push(t[i]);
- i++;
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment