<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>20bits - Latest Comments in Interview Questions: Shuffling an Array</title><link>http://20bits.disqus.com/</link><description></description><atom:link href="https://20bits.disqus.com/interview_questions_shuffling_an_array_20bits/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 20 Nov 2009 11:52:04 -0000</lastBuildDate><item><title>Re: Interview Questions: Shuffling an Array</title><link>http://20bits.com/articles/interview-questions-shuffling-an-array/#comment-23625705</link><description>&lt;p&gt;I was asked this question in an interview. I gave the seemingly correct but subtly wrong solution. Good to know the correct solution.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">gman</dc:creator><pubDate>Fri, 20 Nov 2009 11:52:04 -0000</pubDate></item><item><title>Re: Interview Questions: Shuffling an Array</title><link>http://20bits.com/articles/interview-questions-shuffling-an-array/#comment-3793440</link><description>&lt;p&gt;Hi,&lt;br&gt;Great effort after reading this I really good very nice point how to shuffle array keep it up&lt;br&gt;and post more article also check &lt;a href="http://www.interviewmadeeasy.info/ruby" rel="nofollow noopener" target="_blank" title="http://www.interviewmadeeasy.info/ruby"&gt;Pre Developer&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Thanks&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Hanna</dc:creator><pubDate>Tue, 26 Aug 2008 15:08:39 -0000</pubDate></item><item><title>Re: Interview Questions: Shuffling an Array</title><link>http://20bits.com/articles/interview-questions-shuffling-an-array/#comment-3793439</link><description>&lt;p&gt;What if the source and destination are picked using a random number generator N times? Given that the generator is unifrom, aren't all permutations possible?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andy</dc:creator><pubDate>Sat, 12 Apr 2008 10:14:10 -0000</pubDate></item><item><title>Re: Interview Questions: Shuffling an Array</title><link>http://20bits.com/articles/interview-questions-shuffling-an-array/#comment-3793438</link><description>&lt;p&gt;rue, see here: &lt;a href="http://eigenclass.org/hiki.rb?sort_by+rand+is+biased" rel="nofollow noopener" target="_blank" title="http://eigenclass.org/hiki.rb?sort_by+rand+is+biased"&gt;http://eigenclass.org/hiki....&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">phil</dc:creator><pubDate>Fri, 11 Apr 2008 04:35:19 -0000</pubDate></item><item><title>Re: Interview Questions: Shuffling an Array</title><link>http://20bits.com/articles/interview-questions-shuffling-an-array/#comment-3793437</link><description>&lt;p&gt;rue,&lt;/p&gt;&lt;p&gt;That's not really true, though.  In fact, that "solution" violates multiple requirements of the problems.&lt;/p&gt;&lt;p&gt;One, it's not in-place.  Two, whether or not the distribution is uniform depends on the sorting algorithm that &amp;lt;tt&amp;gt;sort_by&amp;lt;/tt&amp;gt; uses.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jesse</dc:creator><pubDate>Thu, 10 Apr 2008 21:39:02 -0000</pubDate></item><item><title>Re: Interview Questions: Shuffling an Array</title><link>http://20bits.com/articles/interview-questions-shuffling-an-array/#comment-3793436</link><description>&lt;p&gt;Excellent note about the algorithm.&lt;/p&gt;&lt;p&gt;However, since pragmatism trumps all, the "right" way to shuffle an Array in Ruby is this:&lt;/p&gt;&lt;p&gt;  class Array&lt;br&gt;    def shuffle!&lt;br&gt;      replace(array.sort_by { rand })&lt;br&gt;    end&lt;br&gt;  end&lt;/p&gt;&lt;p&gt;As a bonus, it is a language/core lib bug and not your fault if there is a problem with the distribution ;)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">rue</dc:creator><pubDate>Thu, 10 Apr 2008 17:06:49 -0000</pubDate></item><item><title>Re: Interview Questions: Shuffling an Array</title><link>http://20bits.com/articles/interview-questions-shuffling-an-array/#comment-3793435</link><description>&lt;p&gt;cc,&lt;/p&gt;&lt;p&gt;You're right about the first point, but not the second.  Both self.size and size work because we're inside the Array instance.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jesse</dc:creator><pubDate>Thu, 10 Apr 2008 13:00:27 -0000</pubDate></item><item><title>Re: Interview Questions: Shuffling an Array</title><link>http://20bits.com/articles/interview-questions-shuffling-an-array/#comment-3793434</link><description>&lt;p&gt;Note: - I could be wrong here but I think you're code example#1 has a typo, you define variable r and don't use it, and use variable k and don't define it&lt;/p&gt;&lt;p&gt;and shouldn't it be n= self.size in example#1 as well as example#2?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">cc</dc:creator><pubDate>Thu, 10 Apr 2008 06:15:53 -0000</pubDate></item><item><title>Re: Interview Questions: Shuffling an Array</title><link>http://20bits.com/articles/interview-questions-shuffling-an-array/#comment-3793433</link><description>&lt;p&gt;For yet another Ruby implementation of Array#shuffle see Random numbers in Ruby, &lt;a href="http://snippets.dzone.com/posts/show/4697" rel="nofollow noopener" target="_blank" title="http://snippets.dzone.com/posts/show/4697"&gt;http://snippets.dzone.com/p...&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Nice post!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">phil</dc:creator><pubDate>Thu, 10 Apr 2008 05:38:08 -0000</pubDate></item><item><title>Re: Interview Questions: Shuffling an Array</title><link>http://20bits.com/articles/interview-questions-shuffling-an-array/#comment-3793432</link><description>&lt;p&gt;I enjoy reading the posts on this blog.  The posts related to programming are entertaining and help exercise my brain.&lt;/p&gt;&lt;p&gt;&amp;gt;&amp;gt; My next article is going to be more about the interview process rather than specific questions&lt;/p&gt;&lt;p&gt;Regarding the interview process, I've found this post very helpful.&lt;br&gt;&lt;a href="http://www.joelonsoftware.com/articles/GuerrillaInterviewing3.html" rel="nofollow noopener" target="_blank" title="http://www.joelonsoftware.com/articles/GuerrillaInterviewing3.html"&gt;http://www.joelonsoftware.c...&lt;/a&gt;&lt;br&gt;Joel Spolsky has also written a book ("Smart and Gets Things Done") which elaborates on the same ideas in the blog post.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Chris</dc:creator><pubDate>Wed, 09 Apr 2008 14:50:34 -0000</pubDate></item></channel></rss>