ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 13 Nov 2019 18:44:45 +0100How to collect number with minimal number of rounds?https://ask.sagemath.org/question/48700/how-to-collect-number-with-minimal-number-of-rounds/
Has someone an idea how to solve the following problem?
Take the numbers 1,...,100000 and permute them in some way. At first you can make a swap of two numbers. Then you have to compute how many rounds it would take to collect numbers in ascending order. You have to collect numbers by every round by going left to right. In how many ways you can swap two numbers at the beginning to collect numbers in ascending order with minimum number of rounds?
For example, if numbers are from one to five and those at the beginning in order 3, 1, 5, 4, 2, then you can collect them in three rounds: On first round you collect 1, 2, on the second round 3, 4 and finally 5. But you can do one swap in three different ways to collect numbers in two rounds, namely
3, 4, 5, 1, 2
3, 1, 4, 5, 2
3, 1, 2, 4, 5
Five number sequence can be solved easily by brute force and I found an algorithm to collect 1000 numbers, but 100000 numbers needs maybe some kind of trick to compute fast how a specific swap at the beginning affects how many rounds it takes to collect numbers. Mon, 11 Nov 2019 22:05:03 +0100https://ask.sagemath.org/question/48700/how-to-collect-number-with-minimal-number-of-rounds/Comment by John Palmieri for <p>Has someone an idea how to solve the following problem?</p>
<p>Take the numbers 1,...,100000 and permute them in some way. At first you can make a swap of two numbers. Then you have to compute how many rounds it would take to collect numbers in ascending order. You have to collect numbers by every round by going left to right. In how many ways you can swap two numbers at the beginning to collect numbers in ascending order with minimum number of rounds?</p>
<p>For example, if numbers are from one to five and those at the beginning in order 3, 1, 5, 4, 2, then you can collect them in three rounds: On first round you collect 1, 2, on the second round 3, 4 and finally 5. But you can do one swap in three different ways to collect numbers in two rounds, namely</p>
<pre><code>3, 4, 5, 1, 2
3, 1, 4, 5, 2
3, 1, 2, 4, 5
</code></pre>
<p>Five number sequence can be solved easily by brute force and I found an algorithm to collect 1000 numbers, but 100000 numbers needs maybe some kind of trick to compute fast how a specific swap at the beginning affects how many rounds it takes to collect numbers. </p>
https://ask.sagemath.org/question/48700/how-to-collect-number-with-minimal-number-of-rounds/?comment=48701#post-id-48701Your algorithm for 1000 doesn't work for 10000? Anyway, you could look at this: https://www.geeksforgeeks.org/number-of-transpositions-in-a-permutation/ (I have only glanced at it, can't vouch for its accuracy).Tue, 12 Nov 2019 00:53:38 +0100https://ask.sagemath.org/question/48700/how-to-collect-number-with-minimal-number-of-rounds/?comment=48701#post-id-48701Comment by Jaakko Seppälä for <p>Has someone an idea how to solve the following problem?</p>
<p>Take the numbers 1,...,100000 and permute them in some way. At first you can make a swap of two numbers. Then you have to compute how many rounds it would take to collect numbers in ascending order. You have to collect numbers by every round by going left to right. In how many ways you can swap two numbers at the beginning to collect numbers in ascending order with minimum number of rounds?</p>
<p>For example, if numbers are from one to five and those at the beginning in order 3, 1, 5, 4, 2, then you can collect them in three rounds: On first round you collect 1, 2, on the second round 3, 4 and finally 5. But you can do one swap in three different ways to collect numbers in two rounds, namely</p>
<pre><code>3, 4, 5, 1, 2
3, 1, 4, 5, 2
3, 1, 2, 4, 5
</code></pre>
<p>Five number sequence can be solved easily by brute force and I found an algorithm to collect 1000 numbers, but 100000 numbers needs maybe some kind of trick to compute fast how a specific swap at the beginning affects how many rounds it takes to collect numbers. </p>
https://ask.sagemath.org/question/48700/how-to-collect-number-with-minimal-number-of-rounds/?comment=48719#post-id-48719Yes. My efforts are in https://stackoverflow.com/questions/57952706/how-to-collect-numbers-in-ascending-order-with-minimal-number-of-rounds . It looks they takes too much memory or time.Wed, 13 Nov 2019 18:44:45 +0100https://ask.sagemath.org/question/48700/how-to-collect-number-with-minimal-number-of-rounds/?comment=48719#post-id-48719