FizzBuzz: the Programmer's Stairway to Heaven

Daniel natron: thanks for the laugh. :slight_smile:

Had I read the FizzBuzz topic right after the original post, I would not have felt ‘compelled’ to write a solution.

After seeing many other solutions in various languages, it became a fun thing to add. :slight_smile:

Now, off to my hacked Guitar Hero II game, and Stairway! :slight_smile:

Or more precisely, it’s the programmer’s /Smoke on the Water/…

I’m looking for “Bladerunner”'s voice-comp test for programmers

It’s a “Voight-Kampf” test.

OK, that was needlessly nitpicky, but I just couldn’t stop myself.

@blkmage: How are you ever going to gain experience if you don’t try for a job? There’s a lot of code to be written out there, and not all of it needs someone who groks programming really deeply. To quote The Magic Schoolbus: “…get out there, take chances, get messy and make mistakes!” If you’re anything like me, the way to grok programming more fully is to do it, and if you can get paid for it, so much the better.

@Pete: I think a number of programmers (several on my LJ, at any rate) see obfuscated/ultracompact code as a challenge, and a bit of a status symbol: “I can solve this problem in N statements!” “Oh, yeah? I can solve it in N-1 statements!” To some degree, it’s a pissing contest. Looked at from another perspective, though, there’s a certain joy to be had in being able to solve a problem in as few characters as possible. It likely won’t make any difference in execution speed, but it may save a bit of time and tedium on the part of the coder. And readability really is in the eye of the beholder.

Full Disclosure: I’m one of those compulsive FizzBuzz solvers. :slight_smile:

To Jeff’s astonishment people were actually posting solutions to the simple code test. But really Jeff, when will a programmer not try to flex his might and show off his skills a bit. However, some people where trying to one up each other and the started to post code and forgot to do parts of the test, like print the number everywhere else or print FizzBuzz every 15 lines.

The author stated that a decent programmer should be able to write the code in under two minutes. But it’s one of those tests that is so simply you have a chance not to follow the directions. As a lot of the people who were posting solutions didn’t do.

So to me the test is a two-fold question. 1) Can you write a simple program and 2) Can you follow directions?

One more thing - the sort of programmer that reads this blog shouldn’t be above implementing FizzBuzz. Far from it - it’s the sort of thing that one should do periodically to make sure one remembers how. :slight_smile:

Actually, I thought that there was one interesting point about fizzbuzz itself.

The best solution obviously involves using modular arithmetic. If, by some strange twist of fate, the candidate did not know modular arithmetic, would that be an automatic no-hire?

By “not know” I mean that they don’t know that most (all?) computer languages have an operator that gives you the remainder; not that they are completely “math illiterate”.

What if they solved the problem using some other method (say, counters or repeated subtraction)?

I found yesterday’s Fizzbuzz post very encouraging. I am not currently employed as a programmer, but would very much like to be. I could write the Fizzbuzz program without a problem (albeit in BASIC…) and it is encouraging that even at my neophyte level, my genuine fascination with code puts me ahead of such a greater percentage of applicants!

Pete on February 28, 2007 04:23 AM
I’m sorry, but I disagree. I read about half the comments on the last post and didn’t see one genuinely good solution to the problem. None contained a single comment, all utilised hard coded constants and most were just plain obfuscated.

That whooshing sound was the joke flying over your head. The main point of fizzbuzz was that it was incredibly easy a caveman could do it and people in here were just having fun.

As for writing comments: this was an interview question. Did you also scream that they put their code in the default package!!1!!

I have a different take on the programmers taking up the challenges of the FizzBuzz problem (at least on tickletux’s site).

Good programmers are creative, like a challenge and enjoy solving old problems in new, more elegant, ways. The way I’m reading those posts are thoughts on how to make it more elegant and efficient. And a way to show off different programming paradigms and language strengths.

Big, complex, monster problems are solved by breaking them down into smaller, more manageable problems. Seeing how programmers tackle problems in new ways is what I want to see from my candidates.

Love the Wayne’s World reference, but this is different. Guitarists that play Stairway are trying to play it verbatim and often are not very good at it. However, if you played well enough to put your personality into it and make it yours then that’s another thing altogether.

This is how you respond when you get a passionate, creative reaction from programmers in response to your post? That’s really lame. And I’m glad no one listened to you.

Seeing idiomatic Python, Ruby, Scheme, Common Lisp, Haskell, SmallTalk etc. solutions is edifying if you don’t program in that particular language everyday. Lots of the solutions showed examples of some of the great features in those languages. Look at Raganwald’s compose carbonation functions if you don’t believe me. And I’m not ashamed that I learned something from reading that.

The truly frightening thing is the large proportion of ‘solutions’ in the comments that are wrong. Bounds errors, logic errors, failure to read the spec errors, holy cow.

Definitely proof that the “average” developer should be doing something else for a living.

I’d say no - there’s plenty of other (admittedly sub-optimal) ways to do it. I think the point is that they can come up with something that works. You can always optimize later. :slight_smile:

Ugly way to do it (gotta prove I can, y’know) - VBA, since that’s what I’m using at work

Dim number As integer, Dim count3 As integer, Dim count5 As integer
count3 = 0
count5 = 0
For number = 1 To 100
 count3 = count3 + 1
 count5 = count5 + 1
 If (count3 = 3 And count5 = 5) Then
  Debug.Print "FizzBuzz"
  count3 = 0
  count5 = 0
 ElseIf (count3 = 3) Then
  Debug.Print "Fizz"
  count3 = 0
 ElseIf (count5 = 5) Then
  Debug.Print "Buzz"
  count5 = 0
 Else
  Debug.Print number
 End If
Next number

It might have been lost in the noise from yesterday, Jeff, but there are people trying to make Software Engineering a real trade.

For example, The Association of Professional Engineers of British Columbia has a “Software” designation. That’s right - it’s being treated the same as Civil, Mechanical, and Electrical Engineering. You get a degree, you work under other P.Engs for 4 years, then you take a professional practice exam.

http://www.apeg.bc.ca/reg/ProfessionalEngineer.html

It’s a start.

There’s also a planned change to make members of all disciplines take continuing education courses.

Wait a sec. Does that mean you’re lousy if you CAN solve it? Or does it mean your lousy if your not depressed about how lousy all the comp sci grads are? But wait, if I read this blog then all my lousiness is canceled right? I’m gonna put that on my resume.

The problem I saw was that everyone posted solutions in VBA, Windows SCripting Host, VB etc. How is that any solution? I think maybe the FizzBuzz should also analyze what language coders choose. WSH? VBA? your scaring me…

If the people who spent all that time writing code snippets here yesterday had, instead, written to their local universities/colleges/community colleges and asked them how this could happen, maybe something productive could have come from it.

Programmer, police thyself!

Also, I thought Brad’s comment on the rise of HTML was on the mark. After reading through the a good chunk of those comments yesterday, I was talking with the wife about, essentially, the same thing. When we were taking programming classes back in the 70s, there really wasn’t any such thing as a GUI (and certainly no HTML). Your I/O options consisted of “do you want a card punch machine with or without a working ribbon?”

What it works out to is that we spent almost no time programming UI stuff because the UI was primitive and unimportant: algorithms and data structures were important, UI wasn’t.

My son is currently in his 3rd year of a CS degree. His first 2 years were “wasted” with all the stuff necessary to satisfy the “well-rounded person” requirements of the university. The first term of the actual CS degree stuff started with basic programming (FizzBuzz stuff). But, instead of moving on into linked lists and data structures, they spent the next term working on the GUI aspects of programming. Only this term are they back into what we used to consider to be actual programming.

It’s too late to stop the flood of vitriol that will result from that previous paragraph. But, I do want to say that I understand why the school does that: it’s a GUI world now and that stuff needs to be covered. But, what’s the cost of that coverage? FizzBuzz failure?

My thoughts on the problem ‘sorting the sheep from the goats’

http://jimliveshere.spaces.live.com/blog/

ryan on February 28, 2007 08:25 AM

The problem I saw was that everyone posted solutions in VBA, Windows SCripting Host, VB etc. How is that any solution? I think maybe the FizzBuzz should also analyze what language coders choose. WSH? VBA? your scaring me…

Real programmers adapt to the workplace to a certain extent, and are comfortable working with languages that aren’t necessarily their ultimate favorite, in order to Get The Job Done ™.

You cannot always just parade into a job and say “right, toss that lot and lets start over with xyz language”.