<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Enumerating permutations</title>
	<atom:link href="http://cplusplus.co.il/2009/11/14/enumerating-permutations/feed/" rel="self" type="application/rss+xml" />
	<link>http://cplusplus.co.il/2009/11/14/enumerating-permutations/</link>
	<description>Discussing modern C++ and related topics.</description>
	<lastBuildDate>Tue, 31 Jan 2012 01:36:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: rmn</title>
		<link>http://cplusplus.co.il/2009/11/14/enumerating-permutations/#comment-233</link>
		<dc:creator><![CDATA[rmn]]></dc:creator>
		<pubDate>Mon, 28 Dec 2009 15:42:20 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=597#comment-233</guid>
		<description><![CDATA[By the way, the &lt;a href=&quot;http://www.cplusplus.com/reference/algorithm/next_permutation/&quot; rel=&quot;nofollow&quot;&gt;standard algorithm next_permutation&lt;/a&gt; does something pretty similar. It is thoroughly described (along with implementation) &lt;a href=&quot;http://marknelson.us/2002/03/01/next-permutation&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.]]></description>
		<content:encoded><![CDATA[<p>By the way, the <a href="http://www.cplusplus.com/reference/algorithm/next_permutation/" rel="nofollow">standard algorithm next_permutation</a> does something pretty similar. It is thoroughly described (along with implementation) <a href="http://marknelson.us/2002/03/01/next-permutation" rel="nofollow">here</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lorg</title>
		<link>http://cplusplus.co.il/2009/11/14/enumerating-permutations/#comment-98</link>
		<dc:creator><![CDATA[lorg]]></dc:creator>
		<pubDate>Sat, 14 Nov 2009 19:59:29 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=597#comment-98</guid>
		<description><![CDATA[By &quot;this challenge&quot; that a next post will explain I meant the permutation generation challenge :)]]></description>
		<content:encoded><![CDATA[<p>By &#8220;this challenge&#8221; that a next post will explain I meant the permutation generation challenge <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lorg</title>
		<link>http://cplusplus.co.il/2009/11/14/enumerating-permutations/#comment-97</link>
		<dc:creator><![CDATA[lorg]]></dc:creator>
		<pubDate>Sat, 14 Nov 2009 19:57:51 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=597#comment-97</guid>
		<description><![CDATA[You&#039;re welcome, I&#039;m happy that this challenge generated this interest, and many people tried it. By the way, another nice challenge I think you&#039;ll like is generating random numbers according to a given (bell shaped) function, which I gave on my blog here: 
http://www.algorithm.co.il/blogs/index.php/programming/python/small-python-challenge-no-3-random-selection/


One of my next posts will explain some nice mathematical concepts that lie behind the common solution to this challenge. I hope it will be educating as well as interesting.]]></description>
		<content:encoded><![CDATA[<p>You&#8217;re welcome, I&#8217;m happy that this challenge generated this interest, and many people tried it. By the way, another nice challenge I think you&#8217;ll like is generating random numbers according to a given (bell shaped) function, which I gave on my blog here:<br />
<a href="http://www.algorithm.co.il/blogs/index.php/programming/python/small-python-challenge-no-3-random-selection/" rel="nofollow">http://www.algorithm.co.il/blogs/index.php/programming/python/small-python-challenge-no-3-random-selection/</a></p>
<p>One of my next posts will explain some nice mathematical concepts that lie behind the common solution to this challenge. I hope it will be educating as well as interesting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rmn</title>
		<link>http://cplusplus.co.il/2009/11/14/enumerating-permutations/#comment-95</link>
		<dc:creator><![CDATA[rmn]]></dc:creator>
		<pubDate>Sat, 14 Nov 2009 12:25:50 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=597#comment-95</guid>
		<description><![CDATA[Generating a random permutation (shuffling) does not require sorting etc, it can be achieved in a manner like this:
[sourcecode language=&quot;cpp&quot;]
vector&lt;unsigned&gt; v(n);
for (size_t i=0;i&lt;v.size();++i)
  v[i] = i;
for (size_t curr=0;curr&lt;v.size;++curr)
  std::swap(v[n-1-curr], v[rand(0, n-1-curr)]);
[/sourcecode]
(Assuming rand(x,y) returns an unsigned integer between x and y, inclusive)

This one was hard for me because I had to somehow generate all the random values from the single idx parameter, which took some time to get right.

Thanks for the feedback. I really enjoyed the challenge!]]></description>
		<content:encoded><![CDATA[<p>Generating a random permutation (shuffling) does not require sorting etc, it can be achieved in a manner like this:</p>
<pre class="brush: cpp;">
vector&lt;unsigned&gt; v(n);
for (size_t i=0;i&lt;v.size();++i)
  v[i] = i;
for (size_t curr=0;curr&lt;v.size;++curr)
  std::swap(v[n-1-curr], v[rand(0, n-1-curr)]);
</pre>
<p>(Assuming rand(x,y) returns an unsigned integer between x and y, inclusive)</p>
<p>This one was hard for me because I had to somehow generate all the random values from the single idx parameter, which took some time to get right.</p>
<p>Thanks for the feedback. I really enjoyed the challenge!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lorg</title>
		<link>http://cplusplus.co.il/2009/11/14/enumerating-permutations/#comment-94</link>
		<dc:creator><![CDATA[lorg]]></dc:creator>
		<pubDate>Sat, 14 Nov 2009 10:21:18 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=597#comment-94</guid>
		<description><![CDATA[Nice solution!

I have to say though, the challenge on my blog wasn&#039;t exactly about enumerating permutations.
The goal in the challenge was to generate a single, specific permutation, in such a way that all permutations of a given sequence may be generated.

This is a subtle difference - consider the goal of shuffling a sequence of elements. (The &quot;standard&quot; way of doing this is decorating with random, sorting, and then undecorating, but let&#039;s ignore that for a second.)
Using the solution to this challenge and given a random number in the range 1..n!, you could permute the sequence according to that number. Having the solution work in almost O(n) and not going over all &quot;previous&quot; permutations allows this shuffling to be efficient.]]></description>
		<content:encoded><![CDATA[<p>Nice solution!</p>
<p>I have to say though, the challenge on my blog wasn&#8217;t exactly about enumerating permutations.<br />
The goal in the challenge was to generate a single, specific permutation, in such a way that all permutations of a given sequence may be generated.</p>
<p>This is a subtle difference &#8211; consider the goal of shuffling a sequence of elements. (The &#8220;standard&#8221; way of doing this is decorating with random, sorting, and then undecorating, but let&#8217;s ignore that for a second.)<br />
Using the solution to this challenge and given a random number in the range 1..n!, you could permute the sequence according to that number. Having the solution work in almost O(n) and not going over all &#8220;previous&#8221; permutations allows this shuffling to be efficient.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

