<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ed Spencer &#187; geekery</title>
	<atom:link href="http://edspencer.net/tag/geekery/feed" rel="self" type="application/rss+xml" />
	<link>http://edspencer.net</link>
	<description>A Sencha Architect</description>
	<lastBuildDate>Sat, 11 Feb 2012 09:20:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JavaScript FizzBuzz in a tweet</title>
		<link>http://edspencer.net/2009/09/javascript-fizzbuzz-in-a-tweet.html</link>
		<comments>http://edspencer.net/2009/09/javascript-fizzbuzz-in-a-tweet.html#comments</comments>
		<pubDate>Thu, 17 Sep 2009 14:15:54 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[fizzbuzz]]></category>
		<category><![CDATA[geekery]]></category>
		<category><![CDATA[why]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=188</guid>
		<description><![CDATA[<p>The <a href="http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/">FizzBuzz</a> challenge has been around a while but I stumbled across it again after reading <a href="http://gilesbowkett.blogspot.com/2009/09/rails-code-quality-checklist-here.html">another unique Giles Bowkett post</a>.</p>
<p>If you&#8217;re not familiar with FizzBuzz, it&#8217;s a little &#8216;challenge&#8217; designed to test a candidate programmer&#8217;s ability to perform a simple task.  In this case, you just have to print out the numbers from 1 to 100, unless the number is a multiple of 3, when you should instead print &#8220;Fizz&#8221;, 5 in which case you print &#8220;Buzz&#8221;, or both 3 and 5 in which case you print &#8220;FizzBuzz&#8221;.</p>
<p>Here&#8217;s a trivial JavaScript implementation:</p>
<pre class="brush: jscript;">
for (var i=1; i &lt;= 100; i++) {
  if (i % 3 == 0) {
    if (i % 5 == 0) {
      console.log('FizzBuzz');
    } else {
     console.log('Fizz');
   }
  } else if (i % 5 == 0) {
    console.log('Buzz');
  } else {
    console.log(i);
  }
};
</pre>
<p>Pretty simple stuff, but a bit verbose.  I wanted something that would fit into a tweet. It turns out that&#8217;s pretty simple &#8211; this is 133 characters including whitespace, 7 within tolerance for a twitter message:</p>
<pre class="brush: jscript;">
for (var i = 1; i &lt;= 100; i++) {
  var f = i % 3 == 0, b = i % 5 == 0;
  console.log(f ? b ? &quot;FizzBuzz&quot; : &quot;Fizz&quot; : b ? &quot;Buzz&quot; : i);
}
</pre>
<p>Which of course begs the question &#8211; just how short can a JavaScript FizzBuzz implementation be? Here&#8217;s my baseline, which is a tortured and contorted version of the above:</p>
<pre class="brush: jscript;">
for(i=1;i&lt;101;i++){console.log(i%3?i%5?i:&quot;Buzz&quot;:i%5?&quot;Fizz&quot;:&quot;FizzBuzz&quot;)}
</pre>
<p>The above is 71 characters &#8211; I expect you to do better.  The rules are that the only dependency is Firebug&#8217;s console.log being available, and you can&#8217;t replace &#8216;console.log&#8217; for anything else.</p>
<p>Of course, if we did swap &#8216;console.log&#8217; for &#8216;alert&#8217;, the whole thing would fit in a tweet twice, but that would be damn annoying.</p>
<p><strong>Hint:</strong> you can take at least three more characters off the above &#8211; can you see how?</p>
]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/">FizzBuzz</a> challenge has been around a while but I stumbled across it again after reading <a href="http://gilesbowkett.blogspot.com/2009/09/rails-code-quality-checklist-here.html">another unique Giles Bowkett post</a>.</p>
<p>If you&#8217;re not familiar with FizzBuzz, it&#8217;s a little &#8216;challenge&#8217; designed to test a candidate programmer&#8217;s ability to perform a simple task.  In this case, you just have to print out the numbers from 1 to 100, unless the number is a multiple of 3, when you should instead print &#8220;Fizz&#8221;, 5 in which case you print &#8220;Buzz&#8221;, or both 3 and 5 in which case you print &#8220;FizzBuzz&#8221;.</p>
<p>Here&#8217;s a trivial JavaScript implementation:</p>
<pre class="brush: jscript;">
for (var i=1; i &lt;= 100; i++) {
  if (i % 3 == 0) {
    if (i % 5 == 0) {
      console.log('FizzBuzz');
    } else {
     console.log('Fizz');
   }
  } else if (i % 5 == 0) {
    console.log('Buzz');
  } else {
    console.log(i);
  }
};
</pre>
<p>Pretty simple stuff, but a bit verbose.  I wanted something that would fit into a tweet. It turns out that&#8217;s pretty simple &#8211; this is 133 characters including whitespace, 7 within tolerance for a twitter message:</p>
<pre class="brush: jscript;">
for (var i = 1; i &lt;= 100; i++) {
  var f = i % 3 == 0, b = i % 5 == 0;
  console.log(f ? b ? &quot;FizzBuzz&quot; : &quot;Fizz&quot; : b ? &quot;Buzz&quot; : i);
}
</pre>
<p>Which of course begs the question &#8211; just how short can a JavaScript FizzBuzz implementation be? Here&#8217;s my baseline, which is a tortured and contorted version of the above:</p>
<pre class="brush: jscript;">
for(i=1;i&lt;101;i++){console.log(i%3?i%5?i:&quot;Buzz&quot;:i%5?&quot;Fizz&quot;:&quot;FizzBuzz&quot;)}
</pre>
<p>The above is 71 characters &#8211; I expect you to do better.  The rules are that the only dependency is Firebug&#8217;s console.log being available, and you can&#8217;t replace &#8216;console.log&#8217; for anything else.</p>
<p>Of course, if we did swap &#8216;console.log&#8217; for &#8216;alert&#8217;, the whole thing would fit in a tweet twice, but that would be damn annoying.</p>
<p><strong>Hint:</strong> you can take at least three more characters off the above &#8211; can you see how?</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2009/09/javascript-fizzbuzz-in-a-tweet.html/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

