Answer the question
In order to leave comments, you need to log in
How can I set a long command with different parameters for checking in the time command?
I'm not very into Linux yet. There is a /usr/bin/time command . How can I call it correctly if time has its own parameters (-f for example), and the command being checked has a lot of its own. To prevent the parameters from being confused
Answer the question
In order to leave comments, you need to log in
/usr/bin/time [-timeoptions] command [-commandoptions]
Arguments following the command will refer to the command, not time
Recursive algorithm:
function permut8(arr, prepend) {
var i, version, el, result = [];
prepend = prepend || [];
if(arr.length === 1) return [arr];
for( i=0; i<arr.length; i++) {
if( arr.length === 2) {
result.push( prepend.concat( [arr[i], arr[(i+1)%2]] ));
} else {
version = arr.slice();
el = version.splice(i,1);
result = result.concat( permut8( version, prepend.concat(el)));
}
}
return result;
}
var test = permut8( 'abcd'.split('') );
test.map( e=>e.join(' ')).join("\n")
/*
a b c d
a b d c
a c b d
a c d b
a d b c
a d c b
b a c d
b a d c
b c a d
b c d a
b d a c
b d c a
c a b d
c a d b
c b a d
c b d a
c d a b
c d b a
d a b c
d a c b
d b a c
d b c a
d c a b
d c b a
*/
["a", "a"]
we get two identical Non-
function nextLexInPlace(arr){
var i, a = -1, b = -1;
for( i = 0; i < arr.length-1; i++) if(arr[i] < arr[1+i]) a = i;
if( !~a) return; // no more permutations
for( i = a + 1; i < arr.length; i++) if(arr[a] < arr[i]) b = i;
swap(arr, a, b);
a++;
b = arr.length - 1;
while( a < b) swap(arr, a++, b--);
return true;
}
function swap( arr, a, b) {
var xx = arr[a];
arr[a] = arr[b];
arr[b] = xx;
}
function allMutations( source) {
var result = [], arr = source.slice();
result.push( arr.sort().slice());
while( nextLexInPlace(arr)) result.push(arr.slice());
return result;
}
var test = ['a','c','c']; JSON.stringify( allMutations(test))
//
function* permutator(arr) {
var i, a, b;
function swap( arr, a, b) {
var xx = arr[a];
arr[a] = arr[b];
arr[b] = xx;
}
yield arr.slice();
while(true) {
a = -1, b = -1;
for( i = 0; i < arr.length-1; i++) if(arr[i] < arr[1+i]) a = i;
if( !~a) return;
for( i = a + 1; i < arr.length; i++) if(arr[a] < arr[i]) b = i;
swap(arr, a++, b);
b = arr.length - 1;
while( a < b) swap(arr, a++, b--);
yield arr.slice();
}
}
function allMutations( source) {
var all = [], result, G = permutator(source.slice().sort());
while(true) {
result = G.next();
if(result.done) break;
all.push( result.value);
}
return all;
}
var test = ['a','c','c']; JSON.stringify( allMutations(test))
//
google
function* permutation(s) {
if (s.length < 3) {
yield s;
if (s.length == 2) yield s[1] + s[0];
} else {
for (let i = 0; i < s.length; i++) {
let h = s[i];
for (let t of permutation(s.substr(0, i) +
s.substr(i + 1))) yield h + t;
}
}
}
for (let s of permutation("abcd")) {
console.log(s)
}
if all elements in the array are different
function fn(e) {
for (var g = [], b = e.length, h = Math.pow(b, b - 2);; h++) {
var d = h.toString(b),
c = d.length;
if (c > b) break;
c < b && (d = 0 + d);
var f = "";
for (c = 0; c < b; c++) a = parseInt(d[c], b), f += e[a];
e.every(function(b) {
return 0 <= f.indexOf(b)
}) && g.push(f)
}
return g
};
console.log(fn(['a','b','c','d']));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question