Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

FizzBuzz Expand / Collapse
Author
Message
Posted Saturday, February 20, 2010 11:25 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 6:20 PM
Points: 33,078, Visits: 15,192
Comments posted to this topic are about the item FizzBuzz






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #869694
Posted Sunday, February 21, 2010 6:37 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 11:08 PM
Points: 21,231, Visits: 14,940
These sorts of questions could be good. They could also lead down the slippery slope. If speed over quality is the most important - you will end up with a lot of bugs and rework.

I have seen it several times. The devs know the code - but they are more concerned with speed. Under these circumstances, quality and standards are being pushed out the back door. This kind of test could be the type of thing to encourage such practices.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #869985
Posted Sunday, February 21, 2010 9:01 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 7:30 PM
Points: 36,766, Visits: 31,222
For the kind of developers I like to hire, speed, performance, and quality all just happen. It doesn't take any longer to write quality high speed code than it does to write garbage that just happens to get the job done.

I wouldn't set time limits on such tests... I'd just tell them to pretend they're writing code that will go into production and to give it their absolute best shot.

As for the BizzBuzz test... it's a simple and well published solution so if I ever used it as part of a interview, I'd have to pork chop anyone who uses a loop or recursion to solve the problem. I'm not looking for someone who can't even count in a setbased fashion.

Usually though... it doesn't take a test to be able to tell.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #870022
Posted Sunday, February 21, 2010 10:21 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 7:30 PM
Points: 36,766, Visits: 31,222
Heh... I just Googled "FIZZBUZZ SOLUTIONS SQL"... I'm amazed and surprised that some of those folks had the nerve to publish some of the solutions they have. Maybe it's a good test after all.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #870059
Posted Sunday, February 21, 2010 10:29 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 11:08 PM
Points: 21,231, Visits: 14,940
Jeff Moden (2/21/2010)
Heh... I just Googled "FIZZBUZZ SOLUTIONS SQL"... I'm amazed and surprised that some of those folks had the nerve to publish some of the solutions they have. Maybe it's a good test after all.



Did the same. Thought about doing a blog post about it. But then again, there are some decent ones out there that are a part of good blog posts already.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #870062
Posted Sunday, February 21, 2010 10:57 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 11:08 PM
Points: 21,231, Visits: 14,940
Another option would be check out this puzzle roundup by Grant Fritchey.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #870074
Posted Monday, February 22, 2010 12:49 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:21 AM
Points: 1,205, Visits: 923
Jeff Moden (2/21/2010)

I wouldn't set time limits on such tests... I'd just tell them to pretend they're writing code that will go into production and to give it their absolute best shot.


I agree with Jeff about not setting a time limit 'cause I remember when I last went for a job interview I was so nervous that I shaked all over and had they asked me this question then with a time limit I would have failed bitterly. Now just for the heck of it and for those young 'uns going for a job interview, I quickly did this test and to put it together took me 2 minutes ok, maybe 4, but here is my query and please, give me your take on this.

if isnull(object_id('tempdb..##rowtest'),0) <> 0 drop table ##rowtest
select top 100 identity(int,1,1) idkey into ##rowtest from syscolumns
select idkey, case when idkey % 3 = 0 then 'Fizz' else '' end [fizz],
case when idkey % 5 = 0 then 'Buzz' else '' end [buzz],
case when idkey%3 = 0 and idkey%5 = 0 then 'FizzBuzz' else '' end [fizzbuzz]
from ##rowtest

I give you the top 15 results.
idkey fizz buzz fizzbuzz
1
2
3 Fizz
4
5 Buzz
6 Fizz
7
8
9 Fizz
10 Buzz
11
12 Fizz
13
14
15 Fizz Buzz FizzBuzz


Manie Verster
Developer
Johannesburg
South Africa

I can do all things through Christ who strengthens me. - Holy Bible
I am a man of fixed and unbending principles, the first of which is to be flexible at all times. - Everett Mckinley Dirkson (Well, I am trying. - Manie Verster)
Post #870111
Posted Monday, February 22, 2010 1:06 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:21 AM
Points: 1,205, Visits: 923
I checked out Grant Fritchey's article and was, like Jeff, not very pleased to see some while loops but one query attracted my attention and I tested it and I like it.
;WITH Nbrs(n) AS
(
SELECT 1
UNION ALL SELECT 1 + n FROM Nbrs WHERE n < 100
)
SELECT CASE WHEN n%5=0 AND n%3=0 THEN 'BizzBuzz'
WHEN n%3 = 0 THEN 'Bizz'
WHEN n%5 = 0 THEN 'Buzz'
ELSE CAST(n AS VARCHAR(8))
END
FROM Nbrs
OPTION (MAXRECURSION 100);


Manie Verster
Developer
Johannesburg
South Africa

I can do all things through Christ who strengthens me. - Holy Bible
I am a man of fixed and unbending principles, the first of which is to be flexible at all times. - Everett Mckinley Dirkson (Well, I am trying. - Manie Verster)
Post #870116
Posted Monday, February 22, 2010 1:49 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, March 8, 2014 1:19 PM
Points: 30, Visits: 123
It took me 14 minutes and I developed a solution which turned out to closely approximated one or more of what was on Fritchey's page.

What is wrong with using a WHILE and what would be a preferable approach? Also, did you learn of this in a book or where?

Thank you.
Post #870134
Posted Monday, February 22, 2010 2:00 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, March 8, 2014 1:19 PM
Points: 30, Visits: 123
Manie Verster,

I notice that you used a temporary table rather than a table variable. Why did you make that choice?

Thank you.
Post #870141
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse