# FizzBuzz (#126)

**URL:** <https://www.ruby-forum.com/t/fizzbuzz-126/105696>\
**Category:** Ruby\
**Created:** [June 1, 2007, 2:28pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696 "2007-06-01T14:28:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 2:28pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/1 "2007-06-01T14:28:56Z")

</div>

The three rules of Ruby Q.:

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 Q. by submitting ideas as often as you can:

[http://www.rubyquiz.com/](http://www.rubyquiz.com/)

1. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps  
everyone  
on Ruby T. 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.

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 3:35pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/2 "2007-06-01T15:35:05Z")

</div>

In message  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
Ruby Q. wri  
tes:

> 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 Q…

For extra fun, try to do it so the core loop is:

(1…100).each { |x| p x }

-s

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 3:56pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/3 "2007-06-01T15:56:10Z")

</div>

Ruby Q. wrote:

> 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 Q…

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.

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 4:11pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/4 "2007-06-01T16:11:12Z")

</div>

On Jun 1, 9:51 am, Hans F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > numbers which are multiples of both three and five  
> > I feel compelled to point out that it was Microsoft who started this  
> > 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.

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 4:19pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/5 "2007-06-01T16:19:12Z")

</div>

In message [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), Paul  
Novak writes:

> 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.

It took me a good twenty minutes, but then, I’m a total newbie at Ruby,  
and I made about 5 different mistakes. I mean, it took me a while to  
even figure out … Oh. You know, I’m gonna have a hard time saying  
what  
was hard about it for me without spoilers, huh.

I do have it working, though. The idea was obvious, the implementation  
slightly less so, and I’m Probably Doing It Wrong.

-s

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 4:24pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/6 "2007-06-01T16:24:14Z")

</div>

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/000781.html](http://www.codinghorror.com/blog/archives/000781.html) .  
Another one used it to find out if CS graduates can program.

2007/6/1, Hans F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/7 "2007-06-01T16:27:16Z")

</div>

On 6/1/07, Paul N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
> 
> 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

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 4:35pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/8 "2007-06-01T16:35:19Z")

</div>

On 6/1/07, Todd B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 6/1/07, Paul N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/9 "2007-06-01T16:39:20Z")

</div>

On Jun 1, 2007, at 9:34 AM, Robert D. 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 G. II

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 4:37pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/10 "2007-06-01T16:37:20Z")

</div>

On Jun 1, 2007, at 9:25 AM, Todd B. 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 G. II

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 4:53pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/11 "2007-06-01T16:53:22Z")

</div>

In message  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), “Thomas  
Wieczorek” wr  
ites:

> 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/000781.html](http://www.codinghorror.com/blog/archives/000781.html) .  
> Another one used it to find out if CS graduates can program.

What scares me about that page is the number of incorrect answers  
in the comments. Yeesh. I might or might not have gotten it on the  
first try even doing it sanely, but certainly, I would have TESTED  
my code before suggesting that I’d solved the problem.

-s

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/12 "2007-06-01T18:26:36Z")

</div>

James Edward G. 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.

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/13 "2007-06-01T18:33:36Z")

</div>

> 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 B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/14 "2007-06-01T17:13:27Z")

</div>

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

> > question as a screener:  
> > 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 G. II

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/15 "2007-06-01T19:27:44Z")

</div>

Hans F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 - [xkcd: Working for Google](http://xkcd.com/c192.html) )

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 Q. 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?

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/16 "2007-06-01T20:05:48Z")

</div>

On Jun 1, 11:53 am, “Mike M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > people. It’s not, it’s the way to find people who are good at solving  
> > > tool. Maybe it isn’t a problem where you are, but we’ve had people  
> > > interview who couldn’t write a doubly nested loop, or even explain  
> > > When my (now current) boss gave me that question above, she said  
> > > the code overall becomes more elegant or easier to read. I’d much  
> > > find anyone to maintain it".  
> > > Incidentally, my initial answer was:  
> > > I worked with a lead in a java shop that liked to ask this question:  
> > > classes that makes this problem trivial to solve.
> 
> At first I thought this question was too simplistic (much like  
> FizzBuzz), but it really does fletch out the Heros from the Zeros.

Isn’t your test ambiguous? Do you want “Hello World” to become “World  
Hello” or “olleH dlroW”? Or is that part of the test?

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 7:54pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/17 "2007-06-01T19:54:47Z")

</div>

On 6/1/07, Daniel M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> For example, one question we frequently use is "write a function that  
> I’ll also point out that there’s a quite prestigious shop located in  
> perl. (The language I was most familiar with at the time)  
> whether we’re parsing the latest version of the format.  
> desk. Frankly, I’d love some evidence that incoming candidates had  
> Anyone care to identify the language?
> 
> –  
> s=%q( Daniel M. – removed\_email\_address@domain.invalid  
> puts “s=%q(#{s})”,s.to\_a.last )  
> puts “s=%q(#{s})”,s.to\_a.last

I worked with a lead in a java shop that liked to ask this question:

“Write a function that reverses the _words_ in a string” (in java)

Firstly, it would reveal if the candidate listens to the problem and  
then goes about logically solving what was communicated to them (i.e.  
its not reversing the string character by character). If they get  
crafty with the problem then kudos to them, but if they get stuck  
she’ll say that its ok to use java util classes to help solve the  
problem. Secondly if stuck since they claim to be java programmers  
then they should know about the StringTokenizer combined with Stack  
classes that makes this problem trivial to solve.

At first I thought this question was too simplistic (much like  
FizzBuzz), but it really does fletch out the Heros from the Zeros.

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/18 "2007-06-01T20:17:51Z")

</div>

On 6/1/07, Chris S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > now every wannabe shop thinks that’s the way to find smart  
> > > > paper bag, then I see “write code for this” as a useful interviewing  
> > > > to revise their answer. However, we have honestly had people
> > 
> > > techniques that some people might call obscure in production code if  
> > > production environments on the grounds that "we’ll never be able to
> > 
> > then they should know about the StringTokenizer combined with Stack  
> > classes that makes this problem trivial to solve.
> > 
> > At first I thought this question was too simplistic (much like  
> > FizzBuzz), but it really does fletch out the Heros from the Zeros.
> 
> Isn’t your test ambiguous? Do you want “Hello World” to become “World  
> Hello” or “olleH dlroW”? Or is that part of the test?

Ah yes, thanks for jogging my memory, “Write a function that reverses  
the words of a string”

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 9:40pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/19 "2007-06-01T21:40:01Z")

</div>

Hans F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> 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.

Right, which is why FizzBuzz or the minsum question I mentioned (or  
even the “World Hello” problem) are fair game in an interview, but  
“how do you detect a loop in a singly linked list in an efficient,  
O(n) manner” is just not. (Unless the candidate has just made the  
claim that they’ve read all three of Knuth’s books thoroughly and are  
being an ass about it)

(Incidentally, I know of two different solutions to that problem,  
neither of which are likely to ever be of any use to me at all.)

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [June 1, 2007, 8:56pm UTC](https://www.ruby-forum.com/t/fizzbuzz-126/105696/20 "2007-06-01T20:56:57Z")

</div>

On Jun 1, 2007, at 2:17 PM, Mike M. wrote:

> > > then goes about logically solving what was communicated to them
> > 
> > Isn’t your test ambiguous? Do you want “Hello World” to become “World  
> > Hello” or “olleH dlroW”? Or is that part of the test?
> 
> Ah yes, thanks for jogging my memory, “Write a function that reverses  
> the words of a string”

I’d think that would be another opportunity to see how the person  
works. Do they notice the potential ambiguity of the requirement?  
If not, how do they react when the other interpretation (from the one  
they assumed) is pointed out?

Of course, giving one of the specifications:

assert\_equal “World Hello”, reverse\_words(“Hello World”)  
assert\_equal “olleH dlroW”, reverse\_words(“Hello World”)

would clear the matter up (when asked). (And it’s been a couple  
years since I’ve looked at JUnit so just imagine the equivalent Java  
syntax 😉

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

[Next page](https://www.ruby-forum.com/t/fizzbuzz-126/105696.md?page=2)
