L
L
l4m3r2019-07-01 15:41:46
linux
l4m3r, 2019-07-01 15:41:46

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

5 answer(s)
S
Saboteur, 2019-07-01
@l4m3r

/usr/bin/time [-timeoptions] command [-commandoptions]
Arguments following the command will refer to the command, not time

S
Sergey Sokolov, 2017-09-09
@ya_yshel_rabotati_v_teleg

Recursive algorithm:

  1. Each of the letters must be in the first position.
  2. We chose the first one - it is necessary to sort out the rest in all possible ways. We look at the problem in exactly the same way: from (n - 1) letters, you need to sort through all the options. Go to 1)
moped is mine
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
*/
Its disadvantage is that it does not take into account the values ​​of the elements. If there are duplicates, duplicate variants will be created. For example, from ["a", "a"]we get two identical Non-
recursive algorithm.
longclaps says, let's say, let's write so that it generates correctly without repetitions and with repeating elements.
Used the non-recursive algorithm of the Hindu Narayan Pandit, known since the 14th century. From any order in the array, the next iteration is generated, given the lexicographic (alphabetically) sort order.
Moped - mine, washed
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))
// 

And the same moped, but
with generator
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))
// 

L
longclaps, 2017-09-09
@longclaps

google

Sergei Sokolov said that the moped needs to be washed
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)
}

R
Ridz, 2017-09-10
@Ridz

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 question

Ask a Question

731 491 924 answers to any question