[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[QUIZ] FizzBuzz (#126

James Gray

6/1/2007 12:28:00 PM

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.rub...

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

There has been some debate on the proper ways to screen programmers you intend
to hire. A common theory is that you really need to have the programmer write
some code for you to accurately gauge their skill. Exactly what to have them
write is another debate, but the blogosphere has recently been abuzz with this
question as a screener:

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â?.

Pretend you've just walked into a job interview and been hit with this question.
Solve it as you would under such circumstances for this week's Ruby Quiz.

147 Answers

Hans Fugal

6/1/2007 1:52:00 PM

0

Ruby Quiz wrote:

> There has been some debate on the proper ways to screen programmers you intend
> to hire. A common theory is that you really need to have the programmer write
> some code for you to accurately gauge their skill. Exactly what to have them
> write is another debate, but the blogosphere has recently been abuzz with this
> question as a screener:
>
> 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â?.
>
> Pretend you've just walked into a job interview and been hit with this question.
> Solve it as you would under such circumstances for this week's Ruby Quiz.
>

Done, 4 times over. Not a bad quiz though my answers will probably be
considered boring and would be denounced by the fools using this tactic
to hire people as "unimaginative" or "lacking creativity and whizbang
problem-solving skills".

I feel compelled to point out that it was Microsoft who started this
whole mess, and they quickly figured out it was selecting the wrong
people and they don't do it anymore. But the cat's out of the bag, and
now every wannabe shop thinks that's the way to find smart people. It's
not, it's the way to find people who are good at solving puzzles under
pressure, and in the worst case to find people who are good at finding
ridiculously clever (but unreadable/unmaintainable) answers to puzzles
under pressure.

As we all know, good software development is not about solving little
puzzles. It's about reasoning about problems large and small and finding
the most obvious and readable solution (and sometimes optimizing the
inner loop).

Maybe I would try this in a job interview. I might state the problem and
say: "this is not a trick question nor hard - just write the code they
way you normally would." If they write the boring answer, they get
points in my book. If they write some clever answer, they get demerits.
If they can't write code at all, and I didn't realize they wouldn't be
able to, I go sit in a corner and pout.

Paul Novak

6/1/2007 2:09:00 PM

0

On Jun 1, 9:51 am, Hans Fugal <fug...@zianet.com> wrote:
> Ruby Quiz wrote:
> > There has been some debate on the proper ways to screen programmers you intend
> > to hire. A common theory is that you really need to have the programmer write
> > some code for you to accurately gauge their skill. Exactly what to have them
> > write is another debate, but the blogosphere has recently been abuzz with this
> > question as a screener:
>
> > 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".
>
> > Pretend you've just walked into a job interview and been hit with this question.
> > Solve it as you would under such circumstances for this week's Ruby Quiz.
>
> Done, 4 times over. Not a bad quiz though my answers will probably be
> considered boring and would be denounced by the fools using this tactic
> to hire people as "unimaginative" or "lacking creativity and whizbang
> problem-solving skills".
>
> I feel compelled to point out that it was Microsoft who started this
> whole mess, and they quickly figured out it was selecting the wrong
> people and they don't do it anymore. But the cat's out of the bag, and
> now every wannabe shop thinks that's the way to find smart people. It's
> not, it's the way to find people who are good at solving puzzles under
> pressure, and in the worst case to find people who are good at finding
> ridiculously clever (but unreadable/unmaintainable) answers to puzzles
> under pressure.
>
> As we all know, good software development is not about solving little
> puzzles. It's about reasoning about problems large and small and finding
> the most obvious and readable solution (and sometimes optimizing the
> inner loop).
>
> Maybe I would try this in a job interview. I might state the problem and
> say: "this is not a trick question nor hard - just write the code they
> way you normally would." If they write the boring answer, they get
> points in my book. If they write some clever answer, they get demerits.
> If they can't write code at all, and I didn't realize they wouldn't be
> able to, I go sit in a corner and pout.

I do not think there is a lot of room for cleverness in the FizzBuzz
problem. (Actually, I hope I am wrong and we see lots more
suggestions for Extra Fun like Peter's.) My understanding is that
FizzBuzz was intended to screen out candidates that could *not* come
up with working code in a few minutes.

Regards,

Paul.

Thomas Wieczorek

6/1/2007 2:23:00 PM

0

Fizzbuzz has nothing with the Microsoft "How many Ping Pong balls fit
in a Jumbojet" questions. It got a lot of feedback at
http://www.codinghorror.com/blog/archives/0... .
Another one used it to find out if CS graduates can program.

2007/6/1, Hans Fugal <fugalh@zianet.com>:
>
> Done, 4 times over. Not a bad quiz though my answers will probably be
> considered boring and would be denounced by the fools using this tactic
> to hire people as "unimaginative" or "lacking creativity and whizbang
> problem-solving skills".
>
> I feel compelled to point out that it was Microsoft who started this
> whole mess, and they quickly figured out it was selecting the wrong
> people and they don't do it anymore. But the cat's out of the bag, and
> now every wannabe shop thinks that's the way to find smart people. It's
> not, it's the way to find people who are good at solving puzzles under
> pressure, and in the worst case to find people who are good at finding
> ridiculously clever (but unreadable/unmaintainable) answers to puzzles
> under pressure.
>
> As we all know, good software development is not about solving little
> puzzles. It's about reasoning about problems large and small and finding
> the most obvious and readable solution (and sometimes optimizing the
> inner loop).
>
> Maybe I would try this in a job interview. I might state the problem and
> say: "this is not a trick question nor hard - just write the code they
> way you normally would." If they write the boring answer, they get
> points in my book. If they write some clever answer, they get demerits.
> If they can't write code at all, and I didn't realize they wouldn't be
> able to, I go sit in a corner and pout.
>
>

Robert Dober

6/1/2007 2:34:00 PM

0

On 6/1/07, Todd Benson <caduceass@gmail.com> wrote:
> On 6/1/07, Paul Novak <novakps@gmail.com> wrote:
>
> >
> > I do not think there is a lot of room for cleverness in the FizzBuzz
> > problem. (Actually, I hope I am wrong and we see lots more
> > suggestions for Extra Fun like Peter's.) My understanding is that
> > FizzBuzz was intended to screen out candidates that could *not* come
> > up with working code in a few minutes.
Me too I consider this a very good psychological quiz.
My solution is ready and it was a compromise between being clever,
liking the code I have written and *maybe* getting the job.
Given that it took me almost 10 minutes to find that compromise and I
am really looking forward to getting some feedback about the
impression such a solution would make.
James do you have some surprise for us like interpretation from recruiters?

This is an odd looking quiz but I guess it might become one of the
most interesting ones, actually it already is, given this discussion
;)

Cheers
Robert


> >
> > Regards,
> >
> > Paul.
>
>
>
> Immediately coming up with something terribly clever was admittedly my first
> instinct when reading the quiz description. After a few minutes, I realized
> that I'd probably be handing the interviewer no solution at all. I'm that
> type of person; have it work exceptionally well (on all levels), or don't
> bother. Perhaps it's a test of personality more than one of performance
> under pressure.
>
> Todd
>


--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

James Gray

6/1/2007 2:36:00 PM

0

On Jun 1, 2007, at 9:25 AM, Todd Benson wrote:

> Perhaps it's a test of personality more than one of performance
> under pressure.

I happen to agree and I worded the quiz very carefully with that in
mind.

James Edward Gray II

James Gray

6/1/2007 2:39:00 PM

0

On Jun 1, 2007, at 9:34 AM, Robert Dober wrote:

> James do you have some surprise for us like interpretation from
> recruiters?

I think we're already getting plenty of insightful interpretation.

James Edward Gray II



James Gray

6/1/2007 3:13:00 PM

0

On Jun 1, 2007, at 8:55 AM, Hans Fugal wrote:

> Ruby Quiz wrote:
>
>> There has been some debate on the proper ways to screen
>> programmers you intend
>> to hire. A common theory is that you really need to have the
>> programmer write
>> some code for you to accurately gauge their skill. Exactly what
>> to have them
>> write is another debate, but the blogosphere has recently been
>> abuzz with this
>> question as a screener:
>> 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”.
>> Pretend you've just walked into a job interview and been hit with
>> this question.
>> Solve it as you would under such circumstances for this week's
>> Ruby Quiz.
>
> Done, 4 times over.

I almost didn't run it, for this reason. Solutions are everywhere,
even in Ruby.

I do think it's an interesting problem though, more because of what
it's looking for (whatever you believe that is) than the code. I
think how you solve it is important.

James Edward Gray II


Hans Fugal

6/1/2007 4:21:00 PM

0

James Edward Gray II wrote:

>> Done, 4 times over.
>
> I almost didn't run it, for this reason. Solutions are everywhere, even
> in Ruby.

Oh, I meant I had done it in four ways since the quiz had been posted.

Re the comment about not being one of the ping pong balls in a jumbo jet
questions, that's true.

Having not heard of this particular problem, I jumped to the conclusion
that it was one of those "write this seemingly simple program but you're
not cool unless you do it the clever way I'm thinking of" problems. If
it's really used as just a "can you write a simple program" question,
I'm all for that.

Giles Bowkett

6/1/2007 4:33:00 PM

0

> I do not think there is a lot of room for cleverness in the FizzBuzz
> problem. (Actually, I hope I am wrong and we see lots more
> suggestions for Extra Fun like Peter's.) My understanding is that
> FizzBuzz was intended to screen out candidates that could *not* come
> up with working code in a few minutes.

I have the exact same understanding about the intention of FizzBuzz,
but I disagree about the lack of room for cleverness. I've seen it
solved with lazy evaluation and with a Lisp interpreter that ran a
Prolog interpreter (both solutions were written in Ruby).

I've even seen it **unit tested**. (That solution was in Java.)

I wrote some pretty cranky anti-FizzBuzz blog posts a while ago but
still succumbed to the peer pressure and wrote my own (which contains
a small amount of unnecessary code which I didn't spot at the time).

Won't post til the quiz deadline, of course, but just wanted to say, I
think there's a lot of room for cleverness here, although I sometimes
think the clever solutions are a bit perverted in the brainpan.

--
Giles Bowkett

Blog: http://gilesbowkett.bl...
Portfolio: http://www.gilesg...

Daniel Martin

6/1/2007 5:27:00 PM

0

Hans Fugal <fugalh@zianet.com> writes:

> I feel compelled to point out that it was Microsoft who started this
> whole mess, and they quickly figured out it was selecting the wrong
> people and they don't do it anymore. But the cat's out of the bag, and
> now every wannabe shop thinks that's the way to find smart
> people. It's not, it's the way to find people who are good at solving
> puzzles under pressure, and in the worst case to find people who are
> good at finding ridiculously clever (but unreadable/unmaintainable)
> answers to puzzles under pressure.

I think the usefulness of this interview technique depends on what
problem is used and what it is used for. Namely, if the problem is
one that can be solved quickly, and while on autopilot, by pretty much
any decent programmer, and if it is being used simply as a straight
yes/no screen to block people who can't program their way out of a wet
paper bag, then I see "write code for this" as a useful interviewing
tool. Maybe it isn't a problem where you are, but we've had people
claiming five years of programming experience who were unclear on how
two nested loops would execute.

For example, one question we frequently use is "write a function that
takes a two dimensional array and returns the sum of the minimum value
in each row". Now, we understand that people are nervous in
interviews, and we'll occasionally give hints such as "this line here
throws a NullPointerException when you run it", or "that works, unless
the array contains a negative number", and give the candidate a chance
to revise their answer. However, we have honestly had people
interview who couldn't write a doubly nested loop, or even explain
coherently how a sample solution worked. Maybe it'd be easier if we
were interviewing for ruby programmers instead of java programmers.

I'll also point out that there's a quite prestigious shop located in
Mountain View, CA that handed me a whole bunch of "write code in
language X that does this" problems when I interviewed there. (and
they *still* didn't take me - http://xkcd.com... )

On penalizing ridiculous cleverness:

When my (now current) boss gave me that question above, she said
initially "in any language". I scribbled something really short down,
and asked "you probably meant any imperative language, right?", after
which I gave a completely unimaginative imperative solution in
perl. (The language I was most familiar with at the time)

I don't go for the overly clever bizarre stuff at work - that's what
Ruby Quiz is for. Well, okay, I have been known to write bizarre perl
one-liners at the shell prompt, but not for anything that's going to
be run more than once. I have however been known to occasionally use
techniques that some people might call obscure in production code if
the code overall becomes more elegant or easier to read. I'd much
rather build a parser that can read the description of a data record
as provided by a vendor than have fifty lines of mostly cut-and-paste
but conceptually "simple" code that doesn't tell me at a glance
whether we're parsing the latest version of the format.

The point is, yes, maintainability is important, but I really don't
understand the animosity towards "cleverness" that seems to be showing
up here. That sounds to me dangerously close to the same attitude
that keeps ruby and many other non-mainstream languages out of many
production environments on the grounds that "we'll never be able to
find anyone to maintain it".

Also, as a practical matter, I haven't seen this "cleverness" in any
of the subsequent interviews I've conducted from the other side of the
desk. Frankly, I'd love some evidence that incoming candidates had
been exposed to something other than the industry standard languages
and platforms. Exposure to functional programming and the thought
patterns that go with it is a *good* thing. Being able to look at a
problem from multiple angles is a *good* thing. Mental agility?
We're supposed to like that in a candidate.

Incidentally, my initial answer was:

(Plus @@(Min /@ #))&

Anyone care to identify the language?

--
s=%q( Daniel Martin -- martin@snowplow.org
puts "s=%q(#{s})",s.to_a.last )
puts "s=%q(#{s})",s.to_a.last