fredreload Posted September 30, 2016 Posted September 30, 2016 This is the last missing piece I need to complete my compression algorithm, new one. Let's say I have 4 bits with 2 bits set as 1, 0011. The total number of permutations for this number is 0011, 0101, 0110, 1001, 1010, 1100, 6 cases. This can be computed using the calculation. 4! / ((2!)(4-2)!) = 6 Now I want to be able to find the nth sequence, for instance 1st number is 0011, second number is 0101. So if I say n=5, I want to be able to get the 5th permutation sequence 1010 from the initial 0011. How do I do this?
mathematic Posted October 1, 2016 Posted October 1, 2016 You need to define how the permutations are ordered. Permutations give you a total, but they can be in any order.
fredreload Posted October 1, 2016 Author Posted October 1, 2016 (edited) Right as I've mentioned I want 0011 to be 1, so having all the one bits on the right as 1, then slowly move to the left. It really doesn't matter as long as I can track the sequence in an orderly fashion. So I want to be able to derive a sequence using the nth value. For instance I want n=5 to get me 1010 in this case P.S. We know how we can get any binary order using 2 to the power, for instance if I have n=15 I would get 15-2^3-2^2-2^1-2^0 and get 1111 Edited October 1, 2016 by fredreload
Strange Posted October 1, 2016 Posted October 1, 2016 You can find several discussions of this on Stack Overflow and elsewhere. For example:http://stackoverflow.com/questions/7918806/finding-n-th-permutation-without-computing-othershttp://math.stackexchange.com/questions/60742/finding-the-n-th-lexicographic-permutation-of-a-stringhttp://stackoverflow.com/questions/29236556/how-can-i-calculate-n-th-permutation-or-tell-the-lexicographic-order-of-a-givenhttps://codesciencelove.wordpress.com/2013/07/15/finding-the-nth-lexicographic-permutation-of-0123456789/https://apps.topcoder.com/forums/?module=Thread&threadID=645384https://www.quora.com/How-can-we-find-the-lexicographically-Kth-permutation-of-the-sequence-1-N-efficientlyhttp://nrecursions.blogspot.co.uk/2014/02/nth-permutation-without-swapping.htmlhttp://code.activestate.com/recipes/126037-getting-nth-permutation-of-a-sequence/http://www.confusedcoders.com/data-structures/lexicographic-permutation-of-stringhttp://echochamber.me/viewtopic.php?t=104500That is just the first page of results for: https://www.google.com/search?q=generating+nth+permutation
AshBox Posted November 22, 2016 Posted November 22, 2016 You can also find your answer in this link: http://binarytranslator.com/
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now