Note that there are some explanatory texts on larger screens.

plurals
  1. POpermutations with fixed previous element in Python
    primarykey
    data
    text
    <p>So I encountered a problem of permutations with fixed previous element in list. So, I have list, which is an ordered sequence of numbers from 1 till n. </p> <p><strong>EDIT</strong></p> <p>here's a reformuliration of my question: Can you imagine a tree graph? So, 1st level - it's a top (also known as parent) vertex. So, if we have vertex like [1, 2, 3, 4], our next step would be to make permutations, inserting all numbers in the position <strong>n</strong>, it means that in output we would have this:</p> <p>1.1 lvl <code>[1, 2, 3, 4]</code></p> <p>2.1 lvl <code>[1, 2, 4, 3]</code></p> <p>3.1 lvl <code>[1, 3, 4, 2]</code></p> <p>4.1 lvl <code>[2, 3, 4, 1]</code></p> <p>So, then we look at level 1.1 and make permutations of <code>n-1</code>th element ( <code>4</code> is fixed and do not take part in permutation on this level). Output would be:</p> <p>1.1.1 lvl <code>[1, 2, 3, 4]</code></p> <p>1.1.2 lvl <code>[1, 3, 2, 4]</code></p> <p>1.1.3 lvl <code>[2, 3, 1, 4]</code></p> <p>The we took 1.1.1 lvl and fix <code>n-2</code> element (as you can see there is no point to fix 1st element). So, on this level we have fixed <code>3</code>, and <code>4</code>, which is <code>n-1</code>th and <code>n</code>th elemets, outut is:</p> <p>1.1.1.1 lvl <code>[1, 2, 3, 4]</code></p> <p>1.1.1.2 lvl <code>[2, 1, 3, 4]</code></p> <p>We have dinished here, but do not have finish yet. Go on lvl up ( it's level 1.1.2). And permutate it. Here we have fixed <code>n-1</code>th element (it's <code>2</code>) and <code>n</code>th (it's <code>4</code>)</p> <p>1.1.2.1 lvl <code>[1, 3, 2, 4]</code></p> <p>1.1.2.2 lvl <code>[3, 1, 2, 4]</code></p> <p>Finished here. GOTO on upper level. Here fixed <code>1</code> and <code>4</code>. So,</p> <p>1.1.3.1 lvl <code>[2, 3, 1, 4]</code></p> <p>1.1.3.2 lvl <code>[3, 2, 1, 4]</code></p> <p>We have finished the level 1.1 and going to 2.1, where we repeat the same procedure.</p> <p>So, the question is: how to do this in python?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload