<?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: The FizzBuzz Oracle Database Coding Challenge</title>
	<atom:link href="http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/feed/" rel="self" type="application/rss+xml" />
	<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/</link>
	<description>Miscellaneous Random Oracle Topics: Stop, Think, ... Understand</description>
	<lastBuildDate>Thu, 23 May 2013 04:02:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/#comment-3742</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Tue, 02 Aug 2011 15:46:52 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5202#comment-3742</guid>
		<description><![CDATA[utecistu,

I must admit that I did not see your approach as a possible solution until I tried your SQL statement - the problem description does set itself up rather nicely for alphanumeric sorting.  It should be possible to slightly alter your SQL statement to derive another solution using COALESCE rather than GREATEST.]]></description>
		<content:encoded><![CDATA[<p>utecistu,</p>
<p>I must admit that I did not see your approach as a possible solution until I tried your SQL statement &#8211; the problem description does set itself up rather nicely for alphanumeric sorting.  It should be possible to slightly alter your SQL statement to derive another solution using COALESCE rather than GREATEST.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: utecistu</title>
		<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/#comment-3737</link>
		<dc:creator><![CDATA[utecistu]]></dc:creator>
		<pubDate>Tue, 02 Aug 2011 14:51:44 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5202#comment-3737</guid>
		<description><![CDATA[Simple select, NO case, decode, mod :

&lt;pre&gt;
select greatest(to_char(level),
                replace(instr(level/3,&#039;.&#039;),0,&#039;Fizz&#039;),
                replace(instr(level/5,&#039;.&#039;),0,&#039;Buzz&#039;),
                replace(instr(level/15,&#039;.&#039;),0,&#039;FizzBuzz&#039;)
               )
from dual connect by level&lt;=100;
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Simple select, NO case, decode, mod :</p>
<pre>
select greatest(to_char(level),
                replace(instr(level/3,'.'),0,'Fizz'),
                replace(instr(level/5,'.'),0,'Buzz'),
                replace(instr(level/15,'.'),0,'FizzBuzz')
               )
from dual connect by level&lt;=100;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/#comment-3705</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Thu, 28 Jul 2011 01:10:07 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5202#comment-3705</guid>
		<description><![CDATA[Partially inspired by Neil&#039;s solution (it is interesting, but I am still trying to understand how Neil&#039;s solution works - yes, so far it holds the prize ;-) ):
&lt;pre&gt;
WITH N AS
(SELECT
  1 N
FROM
  ALL_OBJECTS
WHERE
  ROWNUM&lt;=10)
SELECT
  DECODE(
    TRUNC(ROUND(ABS(COS(1.04719733*ROWNUM)),1))+
      TRUNC(ROUND(ABS(COS(0.6283184*ROWNUM)),1))*10,
    11,&#039;FizzBuzz&#039;,1,&#039;Fizz&#039;,10,&#039;Buzz&#039;,ROWNUM) FIZZBUZZ,
  TO_CHAR(TO_DATE(ROWNUM,&#039;J&#039;),&#039;Jsp&#039;) FIZZBUZZ2
FROM
  N N1,
  N N2;
  
FIZZBUZZ FIZZBUZZ2
-------- ---------
1        One
2        Two
Fizz     Three
4        Four
Buzz     Five
Fizz     Six
7        Seven
8        Eight
Fizz     Nine
Buzz     Ten
11       Eleven
Fizz     Twelve
13       Thirteen
14       Fourteen
FizzBuzz Fifteen
...
Buzz     Ninety-Five
Fizz     Ninety-Six
97       Ninety-Seven
98       Ninety-Eight
Fizz     Ninety-Nine
Buzz     One Hundred
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Partially inspired by Neil&#8217;s solution (it is interesting, but I am still trying to understand how Neil&#8217;s solution works &#8211; yes, so far it holds the prize <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ):</p>
<pre>
WITH N AS
(SELECT
  1 N
FROM
  ALL_OBJECTS
WHERE
  ROWNUM&lt;=10)
SELECT
  DECODE(
    TRUNC(ROUND(ABS(COS(1.04719733*ROWNUM)),1))+
      TRUNC(ROUND(ABS(COS(0.6283184*ROWNUM)),1))*10,
    11,'FizzBuzz',1,'Fizz',10,'Buzz',ROWNUM) FIZZBUZZ,
  TO_CHAR(TO_DATE(ROWNUM,'J'),'Jsp') FIZZBUZZ2
FROM
  N N1,
  N N2;
  
FIZZBUZZ FIZZBUZZ2
-------- ---------
1        One
2        Two
Fizz     Three
4        Four
Buzz     Five
Fizz     Six
7        Seven
8        Eight
Fizz     Nine
Buzz     Ten
11       Eleven
Fizz     Twelve
13       Thirteen
14       Fourteen
FizzBuzz Fifteen
...
Buzz     Ninety-Five
Fizz     Ninety-Six
97       Ninety-Seven
98       Ninety-Eight
Fizz     Ninety-Nine
Buzz     One Hundred
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neil Johnson</title>
		<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/#comment-3704</link>
		<dc:creator><![CDATA[Neil Johnson]]></dc:creator>
		<pubDate>Wed, 27 Jul 2011 21:12:35 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5202#comment-3704</guid>
		<description><![CDATA[Do I win a prize for least efficient method?

[sourcecode]
select	actual
,	case 	when mod(actual,15) = 0 then &#039;FizzBuzz&#039;
	 	when mod(actual,3) = 0 then &#039;Fizz&#039;
	 	when mod(actual,5) = 0 then &#039;Buzz&#039;
	else	   nvl2(say_thousands,say_thousands&#124;&#124;&#039; &#039;,null)
		&#124;&#124; nvl2(say_hundreds,say_hundreds&#124;&#124;&#039; &#039;,null)
		&#124;&#124; filler
		&#124;&#124; say_tens
	end in_words
from (
	select	actual
	,	case 	when actual_length = 4 then
			thousand_desc&#124;&#124;&#039; thousand&#039;
	end	say_thousands
	,	case 	when hundred_desc is not null then
				hundred_desc&#124;&#124;&#039; hundred&#039;
		end	say_hundreds
	,	case	when actual_length &gt;= 3 and last_2_digits &gt; 0 then
			&#039;and &#039;
		end filler
	,	case 	when last_2_digits between 1 and 15 then
				actual_desc
			when last_2_digits between 16 and 19 then
				unit_desc&#124;&#124;ten_desc
			when last_2_digits between 20 and 99 then
				ten_desc&#124;&#124;&#039; &#039;&#124;&#124;unit_desc
		end	say_tens
	from (
		with bakers as
			(select 1 num,&#039;one&#039; dsc from dual union all
			select 2,&#039;two&#039; from dual union all
			select 3,&#039;three&#039; from dual union all
			select 4,&#039;four&#039; from dual union all
			select 5,&#039;five&#039; from dual union all
			select 6,&#039;six&#039; from dual union all
			select 7,&#039;seven&#039; from dual union all
			select 8,&#039;eight&#039; from dual union all
			select 9,&#039;nine&#039; from dual union all
			select 10,&#039;ten&#039; from dual union all
			select 11,&#039;eleven&#039; from dual union all
			select 12,&#039;twelve&#039; from dual union all
			select 13,&#039;thirteen&#039; from dual union all
			select 14,&#039;fourteen&#039; from dual union all
			select 15,&#039;fifteen&#039; from dual)
		, tens as
			(select 1 num,&#039;teen&#039; dsc from dual union all
			select 2,&#039;twenty&#039; from dual union all
			select 3,&#039;thirty&#039; from dual union all
			select 4,&#039;fourty&#039; from dual union all
			select 5,&#039;fifty&#039; from dual union all
			select 6,&#039;sixty&#039; from dual union all
			select 7,&#039;seventy&#039; from dual union all
			select 8,&#039;eighty&#039; from dual union all
			select 9,&#039;ninety&#039; from dual)
		, number_stack as
			(select	to_char(rownum,&#039;0999&#039;) string_number
			,	rownum actual
			from dual
			connect by level &lt;= 9999)
		select	stack.actual
		,	stack.actual_string
		,	stack.last_2_digits
		,	bakers1.dsc actual_desc
		,	stack.actual_length
		,	bakers4.dsc thousand_desc
		,	bakers3.dsc hundred_desc
		,	stack.hundreds
		,	stack.tens
		,	tens.dsc ten_desc
		,	stack.units
		,	bakers2.dsc unit_desc
		from (
			select 	substr(string_number,length(string_number)-3,1) thousands
			,	substr(string_number,length(string_number)-2,1) hundreds
			,	substr(string_number,length(string_number)-1,1) tens
			,	substr(string_number,length(string_number),1) units
			,	actual
			,	ltrim(string_number,&#039; 0&#039;) actual_string
			,	to_number(ltrim(substr(string_number,length(string_number)-1,2),&#039; 0&#039;)) last_2_digits
			,	length(ltrim(string_number,&#039; 0&#039;)) actual_length
			from	number_stack
		  ) stack
		, bakers bakers1
		, bakers bakers2
		, bakers bakers3
		, bakers bakers4
		, tens
		where 	bakers1.num (+) = stack.last_2_digits
		and	bakers2.num (+) = stack.units
		and	bakers3.num (+) = stack.hundreds
		and	bakers4.num (+) = stack.thousands
		and	tens.num (+) = stack.tens
		and 	stack.actual between 1 and 100 
	)
)
order by actual
/
[/sourcecode]

[sourcecode]
    ACTUAL IN_WORDS
---------- -----------------
         1 one
         2 two
         3 Fizz
         4 four
         5 Buzz
         6 Fizz
         7 seven
         8 eight
         9 Fizz
        10 Buzz
        11 eleven
...
        96 Fizz
        97 ninety seven
        98 ninety eight
        99 Fizz
       100 Buzz
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Do I win a prize for least efficient method?</p>
<pre class="brush: plain; title: ; notranslate">
select	actual
,	case 	when mod(actual,15) = 0 then 'FizzBuzz'
	 	when mod(actual,3) = 0 then 'Fizz'
	 	when mod(actual,5) = 0 then 'Buzz'
	else	   nvl2(say_thousands,say_thousands||' ',null)
		|| nvl2(say_hundreds,say_hundreds||' ',null)
		|| filler
		|| say_tens
	end in_words
from (
	select	actual
	,	case 	when actual_length = 4 then
			thousand_desc||' thousand'
	end	say_thousands
	,	case 	when hundred_desc is not null then
				hundred_desc||' hundred'
		end	say_hundreds
	,	case	when actual_length &gt;= 3 and last_2_digits &gt; 0 then
			'and '
		end filler
	,	case 	when last_2_digits between 1 and 15 then
				actual_desc
			when last_2_digits between 16 and 19 then
				unit_desc||ten_desc
			when last_2_digits between 20 and 99 then
				ten_desc||' '||unit_desc
		end	say_tens
	from (
		with bakers as
			(select 1 num,'one' dsc from dual union all
			select 2,'two' from dual union all
			select 3,'three' from dual union all
			select 4,'four' from dual union all
			select 5,'five' from dual union all
			select 6,'six' from dual union all
			select 7,'seven' from dual union all
			select 8,'eight' from dual union all
			select 9,'nine' from dual union all
			select 10,'ten' from dual union all
			select 11,'eleven' from dual union all
			select 12,'twelve' from dual union all
			select 13,'thirteen' from dual union all
			select 14,'fourteen' from dual union all
			select 15,'fifteen' from dual)
		, tens as
			(select 1 num,'teen' dsc from dual union all
			select 2,'twenty' from dual union all
			select 3,'thirty' from dual union all
			select 4,'fourty' from dual union all
			select 5,'fifty' from dual union all
			select 6,'sixty' from dual union all
			select 7,'seventy' from dual union all
			select 8,'eighty' from dual union all
			select 9,'ninety' from dual)
		, number_stack as
			(select	to_char(rownum,'0999') string_number
			,	rownum actual
			from dual
			connect by level &lt;= 9999)
		select	stack.actual
		,	stack.actual_string
		,	stack.last_2_digits
		,	bakers1.dsc actual_desc
		,	stack.actual_length
		,	bakers4.dsc thousand_desc
		,	bakers3.dsc hundred_desc
		,	stack.hundreds
		,	stack.tens
		,	tens.dsc ten_desc
		,	stack.units
		,	bakers2.dsc unit_desc
		from (
			select 	substr(string_number,length(string_number)-3,1) thousands
			,	substr(string_number,length(string_number)-2,1) hundreds
			,	substr(string_number,length(string_number)-1,1) tens
			,	substr(string_number,length(string_number),1) units
			,	actual
			,	ltrim(string_number,' 0') actual_string
			,	to_number(ltrim(substr(string_number,length(string_number)-1,2),' 0')) last_2_digits
			,	length(ltrim(string_number,' 0')) actual_length
			from	number_stack
		  ) stack
		, bakers bakers1
		, bakers bakers2
		, bakers bakers3
		, bakers bakers4
		, tens
		where 	bakers1.num (+) = stack.last_2_digits
		and	bakers2.num (+) = stack.units
		and	bakers3.num (+) = stack.hundreds
		and	bakers4.num (+) = stack.thousands
		and	tens.num (+) = stack.tens
		and 	stack.actual between 1 and 100 
	)
)
order by actual
/
</pre>
<pre class="brush: plain; title: ; notranslate">
    ACTUAL IN_WORDS
---------- -----------------
         1 one
         2 two
         3 Fizz
         4 four
         5 Buzz
         6 Fizz
         7 seven
         8 eight
         9 Fizz
        10 Buzz
        11 eleven
...
        96 Fizz
        97 ninety seven
        98 ninety eight
        99 Fizz
       100 Buzz
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/#comment-3703</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Wed, 27 Jul 2011 13:52:43 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5202#comment-3703</guid>
		<description><![CDATA[This blog article was made accessible 24 hours ago, so I thought that I would formally share my opinion of why 199 of 200 programmers interviewed simply could not produce the correct answer to the question in less than 10 minutes - I arrived at this conclusion roughly 30 minutes after this blog article was posted.  Revisiting my joke shared in a reply to Mark:
&lt;blockquote&gt;
Two programmers walk into two different bars, the mathematician walks between the bars.
&lt;/blockquote&gt;

What?  Here is the original specification:
&lt;blockquote&gt;
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
&lt;/blockquote&gt;

Think about that specification - is there sufficient information to produce a &quot;correct&quot; solution?  In one of my comments in this article I showed a solution that uses recursion to display the integers from 1 to 100 in reverse numerical order, with the &quot;Fizz&quot; and &quot;Buzz&quot; keywords placed as requested.  Did this solution meet the requirements?  Maybe?  Or should a double quote (&lt;b&gt;&quot;&lt;/b&gt;) have appeared at each end of the keywords?  Should the numbers have appeared in numerical order?  Should I have restricted the numbers output to &lt;b&gt;&lt;i&gt;just&lt;/i&gt;&lt;/b&gt; the integers between 1 and 100 (inclusive)?  We cannot safely assume that only the integer values should be considered - maybe the whole point of the exercise is to indentify those developers that will produce a solution without fully understanding the desired outcome (I did not see this perspective until it was 30 minutes too late).

A mathematician reading &quot;Write a program that prints the numbers from 1 to 100&quot; might produce a very different solution than a typical programmer.  While there are a finite number of integers (whole numbers) between 1 and 100, there are an infinite number of numbers between 1 and 2, between 2 and 3, between 3 and 4, etc.  OK, but computers store numbers in a certain precision that eliminates the possibility of an infinite number of number positions to the right of the decimal, so it might be helpful to pick a datatype for the solution.  For fun, let&#039;s pick the 32 bit datatype BINARY_FLOAT (4 data bytes plus one length byte).  The number 1/3, written in decimal form, has an infinite number of &quot;3&quot; digits to the right of the decimal point.  Let&#039;s see how many digits a 32 bit BINARY_FLOAT supports when holding the value of 1/3:
&lt;pre&gt;
SET SERVEROUTPUT ON
 
DECLARE
  NUM BINARY_FLOAT;
BEGIN
  NUM:=1/3;
  DBMS_OUTPUT.PUT_LINE(NUM);
END;
/
 
3.33333343E-001
 
PL/SQL procedure successfully completed.
&lt;/pre&gt;

It appears that roughly 9 digits to the right of the decimal are supported.  Where did that &quot;4&quot; digit come from?  Let&#039;s check the documentation:
&lt;blockquote&gt;
http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#i16209
BINARY_FLOAT and BINARY_DOUBLE are approximate numeric datatypes. They store approximate representations of decimal values, rather than exact representations. For example, the value 0.1 cannot be exactly represented by either BINARY_DOUBLE or BINARY_FLOAT. They are frequently used for scientific computations. Their behavior is similar to the datatypes FLOAT and DOUBLE in Java and XMLSchema.
&lt;/blockquote&gt;
 
OK, so we must be a little careful when using that datatype (if it is good enough for science, no problem?).  Let&#039;s try an experiment - we will retrieve all of the numbers with 2 decimal places of accuracy between 1 and 100, and produce the requested output:
&lt;pre&gt;
DECLARE
  NUM1 BINARY_FLOAT;
  NUM2 BINARY_FLOAT;
  I BINARY_FLOAT;
  FIZZBUZZ VARCHAR2(8);
BEGIN
  FOR NUM1 IN 1..99 LOOP
    FOR I IN 0..99 LOOP
      NUM2:=NUM1 + 0.01 * I;
   
      IF I = 0 THEN
        IF NUM2/15 = TRUNC(NUM2/15) THEN
          FIZZBUZZ:=&#039;FizzBuzz&#039;;
        ELSE
          IF NUM2/3 = TRUNC(NUM2/3) THEN
            FIZZBUZZ:=&#039;Fizz&#039;;
          ELSE
            IF NUM2/5 = TRUNC(NUM2/5) THEN
              FIZZBUZZ:=&#039;Buzz&#039;;
            ELSE
              FIZZBUZZ:=NULL;
            END IF;
          END IF;
        END IF;
      ELSE
        FIZZBUZZ:=NULL;
      END IF;
      DBMS_OUTPUT.PUT_LINE(COALESCE(FIZZBUZZ,TO_CHAR(NUM2,&#039;990.0000000&#039;)));
    END LOOP;
  END LOOP;
 
  NUM2:=100;
  IF NUM2/15 = TRUNC(NUM2/15) THEN
    FIZZBUZZ:=&#039;FizzBuzz&#039;;
  ELSE
    IF NUM2/3 = TRUNC(NUM2/3) THEN
      FIZZBUZZ:=&#039;Fizz&#039;;
    ELSE
      IF NUM2/5 = TRUNC(NUM2/5) THEN
        FIZZBUZZ:=&#039;Buzz&#039;;
      ELSE
        FIZZBUZZ:=NULL;
      END IF;
    END IF;
  END IF;
  DBMS_OUTPUT.PUT_LINE(COALESCE(FIZZBUZZ,TO_CHAR(NUM2,&#039;990.0000000&#039;)));
END;
/
 
99.9000015
99.9100037
99.9199982
99.9300003
99.9400024
99.9499969
99.9599991
99.9700012
99.9800034
99.9899979
Buzz
&lt;/pre&gt;
 
Nice, although we have a couple seemingly random accuracy problems beyond the first digit to the right of the decimal point (but its good enough for science, so says the documentation).  You can possibly see why I used nested FOR loops - I wanted to make certain that the numbers that are supposed to be integers actually return as integer values.  

Now, extending the previous example, we will retrieve all of the numbers with 7 decimal places of accuracy between 1 and 100, and produce the output that was requested at the start of this blog article:
&lt;pre&gt;
DECLARE
  NUM1 BINARY_FLOAT;
  NUM2 BINARY_FLOAT;
  I BINARY_FLOAT;
  FIZZBUZZ VARCHAR2(8);
BEGIN
  FOR NUM1 IN 1..99 LOOP
    FOR I IN 0..9999999 LOOP
      NUM2:=NUM1 + 0.0000001 * I;
   
      IF I = 0 THEN
        IF NUM2/15 = TRUNC(NUM2/15) THEN
          FIZZBUZZ:=&#039;FizzBuzz&#039;;
        ELSE
          IF NUM2/3 = TRUNC(NUM2/3) THEN
            FIZZBUZZ:=&#039;Fizz&#039;;
          ELSE
            IF NUM2/5 = TRUNC(NUM2/5) THEN
              FIZZBUZZ:=&#039;Buzz&#039;;
            ELSE
              FIZZBUZZ:=NULL;
            END IF;
          END IF;
        END IF;
      ELSE
        FIZZBUZZ:=NULL;
      END IF;
      DBMS_OUTPUT.PUT_LINE(COALESCE(FIZZBUZZ,TO_CHAR(NUM2,&#039;990.0000000&#039;)));
    END LOOP;
  END LOOP;
 
  NUM2:=100;
  IF NUM2/15 = TRUNC(NUM2/15) THEN
    FIZZBUZZ:=&#039;FizzBuzz&#039;;
  ELSE
    IF NUM2/3 = TRUNC(NUM2/3) THEN
      FIZZBUZZ:=&#039;Fizz&#039;;
    ELSE
      IF NUM2/5 = TRUNC(NUM2/5) THEN
        FIZZBUZZ:=&#039;Buzz&#039;;
      ELSE
        FIZZBUZZ:=NULL;
      END IF;
    END IF;
  END IF;
  DBMS_OUTPUT.PUT_LINE(COALESCE(FIZZBUZZ,TO_CHAR(NUM2,&#039;990.0000000&#039;)));
END;
/
&lt;/pre&gt;

Did the output of the above program finish in 10 minutes or less?  If Yes, then try the BINARY_DOUBLE datatype and head out to 15 places to the right of the decimal.

Repeating, I do not think that the problem was that 199 of 200 programmers could not solve the problem - I think that the problem was that 199 (or maybe just 150) of the programmers solved a different problem from what was actually requested.  :-)]]></description>
		<content:encoded><![CDATA[<p>This blog article was made accessible 24 hours ago, so I thought that I would formally share my opinion of why 199 of 200 programmers interviewed simply could not produce the correct answer to the question in less than 10 minutes &#8211; I arrived at this conclusion roughly 30 minutes after this blog article was posted.  Revisiting my joke shared in a reply to Mark:</p>
<blockquote><p>
Two programmers walk into two different bars, the mathematician walks between the bars.
</p></blockquote>
<p>What?  Here is the original specification:</p>
<blockquote><p>
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
</p></blockquote>
<p>Think about that specification &#8211; is there sufficient information to produce a &#8220;correct&#8221; solution?  In one of my comments in this article I showed a solution that uses recursion to display the integers from 1 to 100 in reverse numerical order, with the &#8220;Fizz&#8221; and &#8220;Buzz&#8221; keywords placed as requested.  Did this solution meet the requirements?  Maybe?  Or should a double quote (<b>&#8220;</b>) have appeared at each end of the keywords?  Should the numbers have appeared in numerical order?  Should I have restricted the numbers output to <b><i>just</i></b> the integers between 1 and 100 (inclusive)?  We cannot safely assume that only the integer values should be considered &#8211; maybe the whole point of the exercise is to indentify those developers that will produce a solution without fully understanding the desired outcome (I did not see this perspective until it was 30 minutes too late).</p>
<p>A mathematician reading &#8220;Write a program that prints the numbers from 1 to 100&#8243; might produce a very different solution than a typical programmer.  While there are a finite number of integers (whole numbers) between 1 and 100, there are an infinite number of numbers between 1 and 2, between 2 and 3, between 3 and 4, etc.  OK, but computers store numbers in a certain precision that eliminates the possibility of an infinite number of number positions to the right of the decimal, so it might be helpful to pick a datatype for the solution.  For fun, let&#8217;s pick the 32 bit datatype BINARY_FLOAT (4 data bytes plus one length byte).  The number 1/3, written in decimal form, has an infinite number of &#8220;3&#8243; digits to the right of the decimal point.  Let&#8217;s see how many digits a 32 bit BINARY_FLOAT supports when holding the value of 1/3:</p>
<pre>
SET SERVEROUTPUT ON
 
DECLARE
  NUM BINARY_FLOAT;
BEGIN
  NUM:=1/3;
  DBMS_OUTPUT.PUT_LINE(NUM);
END;
/
 
3.33333343E-001
 
PL/SQL procedure successfully completed.
</pre>
<p>It appears that roughly 9 digits to the right of the decimal are supported.  Where did that &#8220;4&#8243; digit come from?  Let&#8217;s check the documentation:</p>
<blockquote><p>
<a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#i16209" rel="nofollow">http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#i16209</a><br />
BINARY_FLOAT and BINARY_DOUBLE are approximate numeric datatypes. They store approximate representations of decimal values, rather than exact representations. For example, the value 0.1 cannot be exactly represented by either BINARY_DOUBLE or BINARY_FLOAT. They are frequently used for scientific computations. Their behavior is similar to the datatypes FLOAT and DOUBLE in Java and XMLSchema.
</p></blockquote>
<p>OK, so we must be a little careful when using that datatype (if it is good enough for science, no problem?).  Let&#8217;s try an experiment &#8211; we will retrieve all of the numbers with 2 decimal places of accuracy between 1 and 100, and produce the requested output:</p>
<pre>
DECLARE
  NUM1 BINARY_FLOAT;
  NUM2 BINARY_FLOAT;
  I BINARY_FLOAT;
  FIZZBUZZ VARCHAR2(8);
BEGIN
  FOR NUM1 IN 1..99 LOOP
    FOR I IN 0..99 LOOP
      NUM2:=NUM1 + 0.01 * I;
   
      IF I = 0 THEN
        IF NUM2/15 = TRUNC(NUM2/15) THEN
          FIZZBUZZ:='FizzBuzz';
        ELSE
          IF NUM2/3 = TRUNC(NUM2/3) THEN
            FIZZBUZZ:='Fizz';
          ELSE
            IF NUM2/5 = TRUNC(NUM2/5) THEN
              FIZZBUZZ:='Buzz';
            ELSE
              FIZZBUZZ:=NULL;
            END IF;
          END IF;
        END IF;
      ELSE
        FIZZBUZZ:=NULL;
      END IF;
      DBMS_OUTPUT.PUT_LINE(COALESCE(FIZZBUZZ,TO_CHAR(NUM2,'990.0000000')));
    END LOOP;
  END LOOP;
 
  NUM2:=100;
  IF NUM2/15 = TRUNC(NUM2/15) THEN
    FIZZBUZZ:='FizzBuzz';
  ELSE
    IF NUM2/3 = TRUNC(NUM2/3) THEN
      FIZZBUZZ:='Fizz';
    ELSE
      IF NUM2/5 = TRUNC(NUM2/5) THEN
        FIZZBUZZ:='Buzz';
      ELSE
        FIZZBUZZ:=NULL;
      END IF;
    END IF;
  END IF;
  DBMS_OUTPUT.PUT_LINE(COALESCE(FIZZBUZZ,TO_CHAR(NUM2,'990.0000000')));
END;
/
 
99.9000015
99.9100037
99.9199982
99.9300003
99.9400024
99.9499969
99.9599991
99.9700012
99.9800034
99.9899979
Buzz
</pre>
<p>Nice, although we have a couple seemingly random accuracy problems beyond the first digit to the right of the decimal point (but its good enough for science, so says the documentation).  You can possibly see why I used nested FOR loops &#8211; I wanted to make certain that the numbers that are supposed to be integers actually return as integer values.  </p>
<p>Now, extending the previous example, we will retrieve all of the numbers with 7 decimal places of accuracy between 1 and 100, and produce the output that was requested at the start of this blog article:</p>
<pre>
DECLARE
  NUM1 BINARY_FLOAT;
  NUM2 BINARY_FLOAT;
  I BINARY_FLOAT;
  FIZZBUZZ VARCHAR2(8);
BEGIN
  FOR NUM1 IN 1..99 LOOP
    FOR I IN 0..9999999 LOOP
      NUM2:=NUM1 + 0.0000001 * I;
   
      IF I = 0 THEN
        IF NUM2/15 = TRUNC(NUM2/15) THEN
          FIZZBUZZ:='FizzBuzz';
        ELSE
          IF NUM2/3 = TRUNC(NUM2/3) THEN
            FIZZBUZZ:='Fizz';
          ELSE
            IF NUM2/5 = TRUNC(NUM2/5) THEN
              FIZZBUZZ:='Buzz';
            ELSE
              FIZZBUZZ:=NULL;
            END IF;
          END IF;
        END IF;
      ELSE
        FIZZBUZZ:=NULL;
      END IF;
      DBMS_OUTPUT.PUT_LINE(COALESCE(FIZZBUZZ,TO_CHAR(NUM2,'990.0000000')));
    END LOOP;
  END LOOP;
 
  NUM2:=100;
  IF NUM2/15 = TRUNC(NUM2/15) THEN
    FIZZBUZZ:='FizzBuzz';
  ELSE
    IF NUM2/3 = TRUNC(NUM2/3) THEN
      FIZZBUZZ:='Fizz';
    ELSE
      IF NUM2/5 = TRUNC(NUM2/5) THEN
        FIZZBUZZ:='Buzz';
      ELSE
        FIZZBUZZ:=NULL;
      END IF;
    END IF;
  END IF;
  DBMS_OUTPUT.PUT_LINE(COALESCE(FIZZBUZZ,TO_CHAR(NUM2,'990.0000000')));
END;
/
</pre>
<p>Did the output of the above program finish in 10 minutes or less?  If Yes, then try the BINARY_DOUBLE datatype and head out to 15 places to the right of the decimal.</p>
<p>Repeating, I do not think that the problem was that 199 of 200 programmers could not solve the problem &#8211; I think that the problem was that 199 (or maybe just 150) of the programmers solved a different problem from what was actually requested.  <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Radoslav Golian</title>
		<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/#comment-3702</link>
		<dc:creator><![CDATA[Radoslav Golian]]></dc:creator>
		<pubDate>Wed, 27 Jul 2011 11:31:01 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5202#comment-3702</guid>
		<description><![CDATA[You&#039;re right, the 100 is not correct, it should be swapped for 99]]></description>
		<content:encoded><![CDATA[<p>You&#8217;re right, the 100 is not correct, it should be swapped for 99</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Asif Momen</title>
		<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/#comment-3701</link>
		<dc:creator><![CDATA[Asif Momen]]></dc:creator>
		<pubDate>Wed, 27 Jul 2011 10:40:38 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5202#comment-3701</guid>
		<description><![CDATA[Hi Charles,

You made me work on my vacation. ;)

Below are three versions from my side (although the CASE is already mentioned in one of the comments above).

-- simple CASE
&lt;pre&gt;
select level,
       case 
         when mod(level, 3) + mod(level, 5) = 0 then &#039;FizzBuzz&#039;
         when mod(level, 3) = 0 then &#039;Fizz&#039;
         when mod(level, 5) = 0 then &#039;Buzz&#039;
         else to_char(level)
       end txt
  from dual
  connect by level &lt;= 100;
&lt;/pre&gt;
  
--Cascaded DECODE
&lt;pre&gt;
select level,
       decode(mod(level, 3) + mod(level, 5), 0, &#039;FizzBuzz&#039;, decode(mod(level, 3), 0, &#039;Fizz&#039;, decode(mod(level, 5), 0, &#039;Buzz&#039;, to_char(level)))) txt
  from dual
  connect by level &lt;= 100;
&lt;/pre&gt;

-- simple DECODE
&lt;pre&gt;
select level,
       Nvl(decode(mod(level, 3), 0, &#039;Fizz&#039;) &#124;&#124; decode(mod(level, 5), 0, &#039;Buzz&#039;), to_char(level)) txt
  from dual
  connect by level &lt;= 100;
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Hi Charles,</p>
<p>You made me work on my vacation. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Below are three versions from my side (although the CASE is already mentioned in one of the comments above).</p>
<p>&#8211; simple CASE</p>
<pre>
select level,
       case 
         when mod(level, 3) + mod(level, 5) = 0 then 'FizzBuzz'
         when mod(level, 3) = 0 then 'Fizz'
         when mod(level, 5) = 0 then 'Buzz'
         else to_char(level)
       end txt
  from dual
  connect by level &lt;= 100;
</pre>
<p>&#8211;Cascaded DECODE</p>
<pre>
select level,
       decode(mod(level, 3) + mod(level, 5), 0, 'FizzBuzz', decode(mod(level, 3), 0, 'Fizz', decode(mod(level, 5), 0, 'Buzz', to_char(level)))) txt
  from dual
  connect by level &lt;= 100;
</pre>
<p>&#8211; simple DECODE</p>
<pre>
select level,
       Nvl(decode(mod(level, 3), 0, 'Fizz') || decode(mod(level, 5), 0, 'Buzz'), to_char(level)) txt
  from dual
  connect by level &lt;= 100;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/#comment-3700</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Wed, 27 Jul 2011 10:38:45 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5202#comment-3700</guid>
		<description><![CDATA[I promised three more solutions to the problem.  The first two follow.

The solution that just selects the answers you want, and sorts the result into sequential order technique:
&lt;pre&gt;
SELECT
  FIZZBUZZ
FROM
(WITH N AS (
  SELECT
    LEVEL N
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=100)
SELECT
  N.N,
  TO_CHAR(N.N) FIZZBUZZ
FROM
  N
WHERE
  MOD(N,3)&gt;0
  AND MOD(N,5)&gt;0
UNION ALL
SELECT
  N.N,
  &#039;Fizz&#039;
FROM
  N
WHERE
  MOD(N,3)=0
  AND MOD(N,5)&gt;0
UNION ALL
SELECT
  N.N,
  &#039;Buzz&#039;
FROM
  N
WHERE
  MOD(N,3)&gt;0
  AND MOD(N,5)=0
UNION ALL
SELECT
  N.N,
  &#039;FizzBuzz&#039;
FROM
  N
WHERE
  MOD(N,3)=0
  AND MOD(N,5)=0)
ORDER BY
  N;
&lt;/pre&gt;
 
The &quot;I shall confuse you with WITH blocks that reference each other and then left outer join the result to output what I want you to see&quot;: 
&lt;pre&gt;
WITH V1 AS
(SELECT
  ROWNUM N,
  TO_CHAR(ROWNUM) T
FROM
  DUAL
CONNECT BY
  LEVEL&lt;=100),
V2 AS
(SELECT
  ROWNUM*12 N,
  &#039;FizzBuzz&#039; T
FROM
  DUAL
CONNECT BY
  LEVEL&lt;=6),
V3 AS
(SELECT
  *
FROM
  (SELECT
    ROWNUM*3 N,
    &#039;Fizz&#039; T
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=33) V3
WHERE
  V3.N NOT IN 
    (SELECT
      N
    FROM
      V2)),
V4 AS(
SELECT
  *
FROM
  (SELECT
    ROWNUM*5 N,
    &#039;Buzz&#039; T
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=20) V4
WHERE
  V4.N NOT IN 
    (SELECT
      N
    FROM
      V2))
SELECT
  COALESCE(V2.T,V3.T,V4.T,V1.T) FIZZBUZZ
FROM
  V1,
  V2,
  V3,
  V4
WHERE
  V1.N=V2.N(+)
  AND V1.N=V3.N(+)
  AND V1.N=V4.N(+)
ORDER BY
  V1.N;
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>I promised three more solutions to the problem.  The first two follow.</p>
<p>The solution that just selects the answers you want, and sorts the result into sequential order technique:</p>
<pre>
SELECT
  FIZZBUZZ
FROM
(WITH N AS (
  SELECT
    LEVEL N
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=100)
SELECT
  N.N,
  TO_CHAR(N.N) FIZZBUZZ
FROM
  N
WHERE
  MOD(N,3)&gt;0
  AND MOD(N,5)&gt;0
UNION ALL
SELECT
  N.N,
  'Fizz'
FROM
  N
WHERE
  MOD(N,3)=0
  AND MOD(N,5)&gt;0
UNION ALL
SELECT
  N.N,
  'Buzz'
FROM
  N
WHERE
  MOD(N,3)&gt;0
  AND MOD(N,5)=0
UNION ALL
SELECT
  N.N,
  'FizzBuzz'
FROM
  N
WHERE
  MOD(N,3)=0
  AND MOD(N,5)=0)
ORDER BY
  N;
</pre>
<p>The &#8220;I shall confuse you with WITH blocks that reference each other and then left outer join the result to output what I want you to see&#8221;: </p>
<pre>
WITH V1 AS
(SELECT
  ROWNUM N,
  TO_CHAR(ROWNUM) T
FROM
  DUAL
CONNECT BY
  LEVEL&lt;=100),
V2 AS
(SELECT
  ROWNUM*12 N,
  'FizzBuzz' T
FROM
  DUAL
CONNECT BY
  LEVEL&lt;=6),
V3 AS
(SELECT
  *
FROM
  (SELECT
    ROWNUM*3 N,
    'Fizz' T
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=33) V3
WHERE
  V3.N NOT IN 
    (SELECT
      N
    FROM
      V2)),
V4 AS(
SELECT
  *
FROM
  (SELECT
    ROWNUM*5 N,
    'Buzz' T
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=20) V4
WHERE
  V4.N NOT IN 
    (SELECT
      N
    FROM
      V2))
SELECT
  COALESCE(V2.T,V3.T,V4.T,V1.T) FIZZBUZZ
FROM
  V1,
  V2,
  V3,
  V4
WHERE
  V1.N=V2.N(+)
  AND V1.N=V3.N(+)
  AND V1.N=V4.N(+)
ORDER BY
  V1.N;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/#comment-3699</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Wed, 27 Jul 2011 10:30:38 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5202#comment-3699</guid>
		<description><![CDATA[Chadders,

For some reason, I really like that solution.  :-)]]></description>
		<content:encoded><![CDATA[<p>Chadders,</p>
<p>For some reason, I really like that solution.  <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/26/the-fizzbuzz-oracle-database-coding-challenge/#comment-3698</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Wed, 27 Jul 2011 10:28:57 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5202#comment-3698</guid>
		<description><![CDATA[Radoslav,

Three very nice examples!  I will have to spend some time trying to determine how the first 2 of those examples work.  It appears that the third example counts to 101, so maybe we should swap the 100 for 99 in that example.]]></description>
		<content:encoded><![CDATA[<p>Radoslav,</p>
<p>Three very nice examples!  I will have to spend some time trying to determine how the first 2 of those examples work.  It appears that the third example counts to 101, so maybe we should swap the 100 for 99 in that example.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
