do you fail at FizzBuzz? simple prog test

J

John Machin

Terry said:
En Sat, 10 May 2008 22:12:37 -0300, globalrev <[email protected]>
escribió:

| (We used this question last year - some people gave a sensible answer
| in less | than 5 minutes, but others did not even know how to start)

Another approach I do not remember seeing here (under 10 minutes)

fb = ('FizzBuzz', None, None, 'Fizz', None, 'Buzz', 'Fizz',
None, None, 'Fizz', 'Buzz', None, 'Fizz', None, None)
for i in range(1,101): print(fb[i%15] or i) #3.0

"#3.0" is rather cryptic. AFAIK that will work with *any* version of
Python up to 3.0. The "() after "print" are required in 3.0 and optional
in earlier versions.
 
A

alex23

I just can't believe someone applying for a programmer position cannot
provide a sensible anwser in 5 or less minutes.

Try taking a look at the level of discourse in the Google App Engine
group.

It's pretty clear that some - let's say "developers" rather than
"programmers" - developers are simply interested in acquiring usage
patterns for the particular language they're required to develop in.
Being able to extend existing patterns or create new solutions is
completely outside of their scope of interest or ability. My
'favourite' is the "how do I do x?", "can you show me a working
example?", "can you add your example to my code?" sequence, you see a
lot of that.

I'd honestly expect a lot of the current GAE group posters to fail the
FizzBuzz test, especially given that an amazing number of them seem to
be constantly griping about not being able to run production code on
what is currently only a preview framework.

- alex23
 
G

Gabriel Genellina

En Mon, 12 May 2008 14:42:30 -0300, (e-mail address removed)
I just can't believe someone applying for a programmer position cannot
provide a sensible anwser in 5 or less minutes.

For some people, "program" == "form with buttons", excluding all else.
Maybe it's an education problem - "programming in XXX" courses usually
focus on the XXX language itself, assuming (sometimes wrongly) that the
student has a "general programming" background. Worse, I've seen a book on
VB.net (and I think it's not the only one) that is more focused on "how to
use Visual Studio" than teaching the language itself, so it's not
surprising that some people may consider "what's the shortcut to [do some
visual task]" an important "programming skill".

So I think the FizzBuzz problem is a good test to filter out candidates
based on (lack of) practical programming skills. But I don't like that it
is still slightly math-biased (our version said: if multiple of 7 OR ends
in 7 -> replace with the word "Domingo"). I probably would not reject an
answer like this:

for n in range(1,100):
if multiple_of_7(n) or ends_with_7(n): print "Domingo"
else: print n

even if multiple_of_7 or ends_with_7 are incorrect or have some comment
like "I don't remember how to check this". The overall structure is OK,
the guy has decomposed the problem into two smaller subproblems, now it's
time to ask a domain expert about the details... :)
But the poor guy doesn't know that; he's under a lot of stress, nervous,
only has a few minutes remaining and surely thinks "I *have* to write this
in full else I won't get the job!"
I would like to write a similar problem without this non-programming
distracting issues (that is, a problem simple enough to be answered in a
few minutes, that requires only programming skills to be solved, and
leaving out any domain-specific knowledge).
 
B

Bruno Desthuilliers

Kam-Hung Soh a écrit :
You should join the recruitment and interview panel in your organization
to test your faith.

I've done some recruitment - for a programmer position - in my previous
shop , and none of the guys that we interwieved were *that* bad.
 
M

Matthew Woodcraft

Gabriel Genellina said:
I would like to write a similar problem without this non-programming
distracting issues (that is, a problem simple enough to be answered in a
few minutes, that requires only programming skills to be solved, and
leaving out any domain-specific knowledge).

Another reason not to like the FizzBuzz example is that it's quite
closely balanced between two reasonable approaches (whether to just
special-case multiples of 15 and say 'FizzBuzz', or whether to somehow
add the Fizz and the Buzz together in that case). The interviewee might
reasonably guess that this distinction is what's being tested, and get
unnecessarily stressed about it.

-M-
 
J

John Machin

Matthew said:
Another reason not to like the FizzBuzz example is that it's quite
closely balanced between two reasonable approaches (whether to just
special-case multiples of 15 and say 'FizzBuzz', or whether to somehow
add the Fizz and the Buzz together in that case). The interviewee might
reasonably guess that this distinction is what's being tested, and get
unnecessarily stressed about it.

For such a trivial problem, fifteen minutes is more than enough to
present alternative answers. Perhaps the intention is to weed out those
who do become unnecessarily stressed in such circumstances. Employers
like to play tricks to see how interviewees respond e.g. hand over two
pages of a listing of code in language X, announce that there are 10
syntax errors, and ask the interviewee to find and circle all the syntax
errors. Correct answer: 11 circles.
 
M

Mensanator

For such a trivial problem, fifteen minutes is more than enough to
present alternative answers. Perhaps the intention is to weed out those
who do become unnecessarily stressed in such circumstances. Employers
like to play tricks to see how interviewees respond e.g. hand over two
pages of a listing of code in language X, announce that there are 10
syntax errors, and ask the interviewee to find and circle all the syntax
errors. Correct answer: 11 circles.

They get away with that?

The one time I was asked to compose a (hardware) test was
because some interviewee threated to sue claiming
discrimination. So I was asked to make an absolutely
trick-free test.

Such as what's the voltage at point A?

+5v
|
220 ohm
|
+-- A
|
330 ohm
|
ground

Would you be surprised at how many applicants couldn't
figure that out because they forgot to bring their
calculator?

Sure, I had a page from a schematic, but only to ask
how one of the shown T-flip-flops worked.

One female interviewee took one glance at the schematic
and said, "Oh, it's a parity generator."

She got hired.

I'm surprised anyone has to resort to tricks.
 
M

miller.paul.w

As a test, I would leave out the last sentence, and see how many
people (and how fast) figure out than a number can be multiple of
three _and_ five and that the requirement is somehow incomplete ...

Actually, if you leave off the last sentence, what the program should
do when it encounters a multiple of 15 is print "Fizz" and print
"Buzz", in some order, because all multiples of 15 are multiples of 3
and 5. The only difference is, if you don't specify to print
"FizzBuzz" for a multiple of 15, it's perfectly legal to print
"BuzzFizz". :)

On the other hand, asking for clarification regarding multiples of 15
at least shows the applicant is thinking.
 
G

Gabriel Genellina

Such as what's the voltage at point A?

+5v
|
220 ohm
|
+-- A
|
330 ohm
|
ground

Would you be surprised at how many applicants couldn't
figure that out because they forgot to bring their
calculator?

<OT>
Just a few hours ago I was helping a high school boy (senior) with some
chemistry homework. He actually had to use a calculator to evaluate
120*1/1 (and didn't even noticed he got the "same" number until I told
him!)
I hope he'll pass his test tomorrow...
</OT>
 
W

Wolfgang Grafen

globalrev said:
http://reddit.com/r/programming/info/18td4/comments

claims people take a lot of time to write a simple program like this:


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

for i in range(1,101):
if i%3 == 0 and i%5 != 0:
print "Fizz"
elif i%5 == 0 and i%3 != 0:
print "Buzz"
elif i%5 == 0 and i%3 == 0:
print "FizzBuzz"
else:
print i


is there a better way than my solution? is mine ok?

Your example is comprehensive compared to many other suggestions which
is an advantage IMO. I minimised it further

for i in range(start, stop, step):
if not i%15:
print "FizzBuzz"
elif not i%3:
print "Fizz"
elif not i%5:
print "Buzz"
else:
print i

Best regards

Wolfgang
 
C

castironpi

globalrev schrieb:










Your example is comprehensive compared to many other suggestions which
is an advantage IMO. I minimised it further

for i in range(start, stop, step):
     if not i%15:
         print "FizzBuzz"
     elif not i%3:
         print "Fizz"
     elif not i%5:
         print "Buzz"
     else:
         print i

Best regards

Wolfgang- Hide quoted text -

- Show quoted text -

This one eliminates the modulo operation.

dyn= list( xrange( 1, 101 ) )
for i in xrange( 1, len( dyn ), 3 ):
dyn[ i ]= ''
for i in xrange( 1, len( dyn ), 5 ):
dyn[ i ]= ''
for i in xrange( 1, len( dyn ), 3 ):
dyn[ i ]+= 'Fizz'
for i in xrange( 1, len( dyn ), 5 ):
dyn[ i ]+= 'Buzz'
for d in dyn:
print d

Can we compare?
 
T

Tobiah

Or to allow the numbers 3 and 5 to be easily changed:

for i in range(1, 101):
print 'fizz' * (not i % 3) + 'buzz' * (not i % 5) or i

Tobiah

for i in range(1,100):
print ('fizz','','')[i%3] + ('buzz','','','','')[i%5] or i
"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".

for i in range(1,101):
if i%3 == 0 and i%5 != 0:
print "Fizz"
elif i%5 == 0 and i%3 != 0:
print "Buzz"
elif i%5 == 0 and i%3 == 0:
print "FizzBuzz"
else:
print i


is there a better way than my solution? is mine ok?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top