<?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/"
		>
<channel>
	<title>Comments on: Programming job interview challenge</title>
	<atom:link href="http://igoro.com/archive/programming-job-interview-challenge/feed/" rel="self" type="application/rss+xml" />
	<link>http://igoro.com/archive/programming-job-interview-challenge/</link>
	<description>On programming, technology, and random things of interest</description>
	<lastBuildDate>Thu, 02 Feb 2012 01:36:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: Jake</title>
		<link>http://igoro.com/archive/programming-job-interview-challenge/comment-page-1/#comment-35570</link>
		<dc:creator>Jake</dc:creator>
		<pubDate>Sun, 15 Jan 2012 14:58:36 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/programming-job-interview-challenge/#comment-35570</guid>
		<description>Sorry, I forgot to mention what was obvious to me - 64kb array you use to reverse 2 bytes at a time.</description>
		<content:encoded><![CDATA[<p>Sorry, I forgot to mention what was obvious to me &#8211; 64kb array you use to reverse 2 bytes at a time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jake</title>
		<link>http://igoro.com/archive/programming-job-interview-challenge/comment-page-1/#comment-35569</link>
		<dc:creator>Jake</dc:creator>
		<pubDate>Sun, 15 Jan 2012 14:56:10 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/programming-job-interview-challenge/#comment-35569</guid>
		<description>Igor &amp; co - as long as you use a pre-cached array, it does not really matter how you init it - fast or slow c trick make no diff.
The only reason to use bit tricks here is if you can make the reverse function faster than the array lookup. The array lookup is very cheap so unbeatable.

If array lookup is &quot;free&quot;, I&#039;d expect a &quot;good&quot; answer to at least mention that you can use 64kb array. How about a 4gb array?

What about cache misses? this could cost you 200 cycles per 64 bytes. So it might be worthwhile to skip the array for an input shorter than, say, 100 cycles to process, for the 256 byte array. Probably a lot more for bigger ones (which renders it a good answer only in theory). Micro benchmarks will not give you the answer in this case, only real life probing.</description>
		<content:encoded><![CDATA[<p>Igor &amp; co &#8211; as long as you use a pre-cached array, it does not really matter how you init it &#8211; fast or slow c trick make no diff.<br />
The only reason to use bit tricks here is if you can make the reverse function faster than the array lookup. The array lookup is very cheap so unbeatable.</p>
<p>If array lookup is &#8220;free&#8221;, I&#8217;d expect a &#8220;good&#8221; answer to at least mention that you can use 64kb array. How about a 4gb array?</p>
<p>What about cache misses? this could cost you 200 cycles per 64 bytes. So it might be worthwhile to skip the array for an input shorter than, say, 100 cycles to process, for the 256 byte array. Probably a lot more for bigger ones (which renders it a good answer only in theory). Micro benchmarks will not give you the answer in this case, only real life probing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor Ostrovsky</title>
		<link>http://igoro.com/archive/programming-job-interview-challenge/comment-page-1/#comment-9395</link>
		<dc:creator>Igor Ostrovsky</dc:creator>
		<pubDate>Tue, 12 Jul 2011 22:28:07 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/programming-job-interview-challenge/#comment-9395</guid>
		<description>Philip: Yes, that approach certainly works. In fact, that&#039;s the approach I was referring to when I said that &quot;There is an obvious solution which uses a for loop and some bit manipulation&quot;</description>
		<content:encoded><![CDATA[<p>Philip: Yes, that approach certainly works. In fact, that&#8217;s the approach I was referring to when I said that &#8220;There is an obvious solution which uses a for loop and some bit manipulation&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Philip</title>
		<link>http://igoro.com/archive/programming-job-interview-challenge/comment-page-1/#comment-9202</link>
		<dc:creator>Philip</dc:creator>
		<pubDate>Sun, 10 Jul 2011 23:23:20 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/programming-job-interview-challenge/#comment-9202</guid>
		<description>It seems commenting engine ate some parts of C++ code in my last comment.
&lt;a href=&quot;http://pastebin.com/qUxJdnbR&quot; rel=&quot;nofollow&quot;&gt;Here&lt;/a&gt; is the original.</description>
		<content:encoded><![CDATA[<p>It seems commenting engine ate some parts of C++ code in my last comment.<br />
<a href="http://pastebin.com/qUxJdnbR" rel="nofollow">Here</a> is the original.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Philip</title>
		<link>http://igoro.com/archive/programming-job-interview-challenge/comment-page-1/#comment-9200</link>
		<dc:creator>Philip</dc:creator>
		<pubDate>Sun, 10 Jul 2011 23:04:12 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/programming-job-interview-challenge/#comment-9200</guid>
		<description>There is another interesting approach to inverting bits problem.

Let us assume you need to reverse each number in range [0 .. 2^n - 1]. Notice that &quot;increment some number&quot; means delete (i.e. change to 0&#039;es) a group of 1&#039;s at the end of it and place 1 before this group. So if you know reversed(m) and want to get reversed(m + 1) then all you need is to delete a group of ones at the beginning of reversed(m) and place 1 right after them.

Here is the code:

int MAX = (1 &lt;&lt; n);
for (int i = 0, revi = 0; i &gt; 1);
  for (; revi &amp; bit; bit &gt;&gt;= 1)
    revi ^= bit;
  revi &#124;= bit;
  
  reversed[i] = revi;
}


Careful analysis shows, that this algorithm works in linear time.</description>
		<content:encoded><![CDATA[<p>There is another interesting approach to inverting bits problem.</p>
<p>Let us assume you need to reverse each number in range [0 .. 2^n - 1]. Notice that &#8220;increment some number&#8221; means delete (i.e. change to 0&#8242;es) a group of 1&#8242;s at the end of it and place 1 before this group. So if you know reversed(m) and want to get reversed(m + 1) then all you need is to delete a group of ones at the beginning of reversed(m) and place 1 right after them.</p>
<p>Here is the code:</p>
<p>int MAX = (1 &lt;&lt; n);<br />
for (int i = 0, revi = 0; i &gt; 1);<br />
  for (; revi &amp; bit; bit &gt;&gt;= 1)<br />
    revi ^= bit;<br />
  revi |= bit;</p>
<p>  reversed[i] = revi;<br />
}</p>
<p>Careful analysis shows, that this algorithm works in linear time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duc</title>
		<link>http://igoro.com/archive/programming-job-interview-challenge/comment-page-1/#comment-2637</link>
		<dc:creator>Duc</dc:creator>
		<pubDate>Sun, 10 Apr 2011 16:38:01 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/programming-job-interview-challenge/#comment-2637</guid>
		<description>Dear Igor,

   Yes it is interesting crazy :-), :-), :-).
   Also, it is also slower than your version (compiler
   can not compete with handcraft-assembler code).

Regards
DL</description>
		<content:encoded><![CDATA[<p>Dear Igor,</p>
<p>   Yes it is interesting crazy <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> , <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> , <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .<br />
   Also, it is also slower than your version (compiler<br />
   can not compete with handcraft-assembler code).</p>
<p>Regards<br />
DL</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor Ostrovsky</title>
		<link>http://igoro.com/archive/programming-job-interview-challenge/comment-page-1/#comment-2458</link>
		<dc:creator>Igor Ostrovsky</dc:creator>
		<pubDate>Wed, 23 Feb 2011 19:20:13 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/programming-job-interview-challenge/#comment-2458</guid>
		<description>Duc: Crazy C tricks with packed structs. :)

Interesting.</description>
		<content:encoded><![CDATA[<p>Duc: Crazy C tricks with packed structs. <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Interesting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duc</title>
		<link>http://igoro.com/archive/programming-job-interview-challenge/comment-page-1/#comment-2457</link>
		<dc:creator>Duc</dc:creator>
		<pubDate>Wed, 23 Feb 2011 18:33:35 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/programming-job-interview-challenge/#comment-2457</guid>
		<description>Dear Igor,

   Sorry about the last post; something is missing;
   I am reposting the main body. Sorry again. Thanks
   again.

=============================================================
    uint16 i;
    for (i = 0; i f = cbi-&gt;e;
        cba-&gt;s = cbi-&gt;sv;
        cba-&gt;t = cbi-&gt;sx;
        cba-&gt;fo = cbi-&gt;ff;
        cba-&gt;ff = cbi-&gt;fo;
        cba-&gt;sx = cbi-&gt;t;
        cba-&gt;sv = cbi-&gt;s;
        cba-&gt;e = cbi-&gt;f;
      }
    printf (&quot;I am done :-), :-), :-)&quot;);

========================================================</description>
		<content:encoded><![CDATA[<p>Dear Igor,</p>
<p>   Sorry about the last post; something is missing;<br />
   I am reposting the main body. Sorry again. Thanks<br />
   again.</p>
<p>=============================================================<br />
    uint16 i;<br />
    for (i = 0; i f = cbi-&gt;e;<br />
        cba-&gt;s = cbi-&gt;sv;<br />
        cba-&gt;t = cbi-&gt;sx;<br />
        cba-&gt;fo = cbi-&gt;ff;<br />
        cba-&gt;ff = cbi-&gt;fo;<br />
        cba-&gt;sx = cbi-&gt;t;<br />
        cba-&gt;sv = cbi-&gt;s;<br />
        cba-&gt;e = cbi-&gt;f;<br />
      }<br />
    printf (&#8220;I am done <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> , <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> , <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> &#8221;);</p>
<p>========================================================</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duc</title>
		<link>http://igoro.com/archive/programming-job-interview-challenge/comment-page-1/#comment-2456</link>
		<dc:creator>Duc</dc:creator>
		<pubDate>Wed, 23 Feb 2011 18:29:36 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/programming-job-interview-challenge/#comment-2456</guid>
		<description>Dear Igor,

  Cool stuff and thanks.

  What do you think about the below implementation?

    typedef unsigned char uint8;
    typedef struct ch_bit char_bit;
    struct ch_bit
    {
      uint8 f:1;
      uint8 s:1;
      uint8 t:1;
      uint8 fo:1;
      uint8 ff:1;
      uint8 sx:1;
      uint8 sv:1;
      uint8 e:1;
    } __attribute__ ((__packed__));

    char_bit reverse_array[256];
    char_bit *cbi;
    char_bit *cba;
    uint8 i;
    for (i = 0; i f = cbi-&gt;e;
        cba-&gt;s = cbi-&gt;sv;
        cba-&gt;t = cbi-&gt;sx;
        cba-&gt;fo = cbi-&gt;ff;
        cba-&gt;ff = cbi-&gt;fo;
        cba-&gt;sx = cbi-&gt;t;
        cba-&gt;sv = cbi-&gt;s;
        cba-&gt;e = cbi-&gt;f;
      }
    printf (&quot;I am done :-), :-), :-)&quot;);
  
    This is not cool as yours. But implementation-wise it is
    much simpler; speed-wise I think it is fast too.

    Again, thanks for cool posts.

Regards
Duc</description>
		<content:encoded><![CDATA[<p>Dear Igor,</p>
<p>  Cool stuff and thanks.</p>
<p>  What do you think about the below implementation?</p>
<p>    typedef unsigned char uint8;<br />
    typedef struct ch_bit char_bit;<br />
    struct ch_bit<br />
    {<br />
      uint8 f:1;<br />
      uint8 s:1;<br />
      uint8 t:1;<br />
      uint8 fo:1;<br />
      uint8 ff:1;<br />
      uint8 sx:1;<br />
      uint8 sv:1;<br />
      uint8 e:1;<br />
    } __attribute__ ((__packed__));</p>
<p>    char_bit reverse_array[256];<br />
    char_bit *cbi;<br />
    char_bit *cba;<br />
    uint8 i;<br />
    for (i = 0; i f = cbi-&gt;e;<br />
        cba-&gt;s = cbi-&gt;sv;<br />
        cba-&gt;t = cbi-&gt;sx;<br />
        cba-&gt;fo = cbi-&gt;ff;<br />
        cba-&gt;ff = cbi-&gt;fo;<br />
        cba-&gt;sx = cbi-&gt;t;<br />
        cba-&gt;sv = cbi-&gt;s;<br />
        cba-&gt;e = cbi-&gt;f;<br />
      }<br />
    printf (&#8220;I am done <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> , <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> , <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> &#8221;);</p>
<p>    This is not cool as yours. But implementation-wise it is<br />
    much simpler; speed-wise I think it is fast too.</p>
<p>    Again, thanks for cool posts.</p>
<p>Regards<br />
Duc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Skip lists are fascinating! &#124; Igor Ostrovsky Blogging</title>
		<link>http://igoro.com/archive/programming-job-interview-challenge/comment-page-1/#comment-568</link>
		<dc:creator>Skip lists are fascinating! &#124; Igor Ostrovsky Blogging</dc:creator>
		<pubDate>Wed, 09 Sep 2009 07:31:23 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/programming-job-interview-challenge/#comment-568</guid>
		<description>[...] Programming job interview challenge [igoro.com] [...]</description>
		<content:encoded><![CDATA[<p>[...] Programming job interview challenge [igoro.com] [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

