473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

do you fail at FizzBuzz? simple prog test

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?
Jun 27 '08 #1
35 2178
globalrev wrote:
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?
Try doing it using %3 and %5 only once each.
Jun 27 '08 #2
On Sun, 11 May 2008 11:12:37 +1000, globalrev <sk*******@yahoo.sewrote:
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?
Looks OK to me.

A different version, and I test for multiples of 3 and 5 first:

map(lambda x: (not x%3 and not x%5 and "FizzBuzz") or (not x%3 and "Fizz")
or (not x%5 and "Buzz") or x, xrange(1,101))

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>
Jun 27 '08 #3
On May 10, 8:12�pm, globalrev <skanem...@yahoo.sewrote:
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?
Define better.
>>f = ['','','Fizz']*100
b = ['','','','','Buzz']*100
for i in xrange(1,100):
fb = f[i-1]+b[i-1]
if fb=='':
print i
else:
print fb
Jun 27 '08 #4
On 2008-05-11, John Machin <sj******@lexicon.netwrote:
>"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?

Try doing it using %3 and %5 only once each.
for i in xrange(101):
print (("","Fizz")[i%3==0] + ("","Buzz")[i%5==0]) or str(i)

His is better though, since it's more obvious what's intended.

Here's one that's less opaque

for i in xrange(101):
s = ""
if i%3 == 0: s += "Fizz"
if i%5 == 0: s += "Buzz"
if s:
print s
else:
print i

There are dozens of other ways to do it.
--
Grant Edwards grante Yow! ... or were you
at driving the PONTIAC that
visi.com HONKED at me in MIAMI last
Tuesday?
Jun 27 '08 #5
On Sat, 10 May 2008 18:12:37 -0700, globalrev wrote:
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?
['%s%s' % (not i%3 and 'Fizz' or '', not i%5 and 'Buzz' or '')
or str(i) for i in xrange(1, 101)]

-- Ivan
Jun 27 '08 #6
On Sun, 11 May 2008 04:26:10 +0000, Ivan Illarionov wrote:
On Sat, 10 May 2008 18:12:37 -0700, globalrev wrote:
>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?

['%s%s' % (not i%3 and 'Fizz' or '', not i%5 and 'Buzz' or '')
or str(i) for i in xrange(1, 101)]

-- Ivan
or, more correctly, if you actually need to "print":

sys.stdout.write('\n'.join('%s%s' %
(not i%3 and 'Fizz' or '', not i%5 aBuzz' or '')
or str(i)
for i in xrange(1, 101)))

-- Ivan
Jun 27 '08 #7
On May 11, 1:24 pm, Mensanator <mensana...@aol.comwrote:
On May 10, 8:12�pm, globalrev <skanem...@yahoo.sewrote:
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?

Define better.
>f = ['','','Fizz']*100
b = ['','','','','Buzz']*100
for i in xrange(1,100):

fb = f[i-1]+b[i-1]
if fb=='':
print i
else:
print fb
You seem to have an unfortunate fixation on 100. Consider changing the
above instances to 34, 20, and 101.
Jun 27 '08 #8
On May 11, 12:04Â*am, John Machin <sjmac...@lexicon.netwrote:
On May 11, 1:24 pm, Mensanator <mensana...@aol.comwrote:


On May 10, 8:12�pm, globalrev <skanem...@yahoo.sewrote:
>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?
Define better.
>>f = ['','','Fizz']*100
>>b = ['','','','','Buzz']*100
>>for i in xrange(1,100):
Â* Â* Â* Â* fb = f[i-1]+b[i-1]
Â* Â* Â* Â* if fb=='':
Â* Â* Â* Â* Â* Â* Â* Â* print i
Â* Â* Â* Â* else:
Â* Â* Â* Â* Â* Â* Â* Â* print fb

You seem to have an unfortunate fixation on 100. Consider changing the
above instances to 34, 20, and 101.
Ok, I agree with 101, but I wouldn't necessarily
say the others were unfortunate. You might be
surprised at how often such fixations discover
bugs, something that I have a gift for.
Jun 27 '08 #9
En Sat, 10 May 2008 22:12:37 -0300, globalrev <sk*******@yahoo.seescribió:
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?
Is it correct? Did you get at it in less than 15 minutes? If so, then it's OK.
The original test was not "write the most convoluted algorithm you can think of", nor "write the best program to solve this". It was a *practical* test: if you can't get anything remotely working for such a simple problem in 15 minutes, we're not interested in your services.

(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)

--
Gabriel Genellina

Jun 27 '08 #10
On 12 Mag, 09:00, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Sat, 10 May 2008 22:12:37 -0300, globalrev <skanem...@yahoo.seescribió:


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?

Is it correct? Did you get at it in less than 15 minutes? If so, then it'sOK.
The original test was not "write the most convoluted algorithm you can think of", nor "write the best program to solve this". It was a *practical* test: if you can't get anything remotely working for such a simple problem in 15 minutes, we're not interested in your services.

(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)

--
Gabriel Genellina- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -
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 ...

Ciao
-----
FB
Jun 27 '08 #11
On May 11, 4:36*am, Grant Edwards <gra...@visi.comwrote:
On 2008-05-11, John Machin <sjmac...@lexicon.netwrote:
"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?
Try doing it using %3 and %5 only once each.

for i in xrange(101):
* * print (("","Fizz")[i%3==0] + ("","Buzz")[i%5==0]) or str(i)

His is better though, since it's more obvious what's intended.

Here's one that's less opaque

for i in xrange(101):
* * s = ""
* * if i%3 == 0: s += "Fizz"
* * if i%5 == 0: s += "Buzz"
* * if s:
* * * * print s
* * else:
* * * * print i
Let's not forget to generalise the problem and code it OOP-style :)

class FizzBuzzer(object):
def __init__(self, *fizzles):
self.fizzles = fizzles
def translate(self, n):
return ''.join(val for (p, val) in self.fizzles if not n%p) or
n
def range(self, start, stop=None, step=None):
if stop is None:
start, stop = 0, start
if step is None:
step = 1
for n in xrange(start, stop, step):
yield self.translate(n)
def __getitem__(self, obj):
if isinstance(obj, slice):
return self.range(obj.start, obj.stop, obj.step)
else:
return self.translate(obj)

# FizzBuzzer in action:
>>fizzbuzz = FizzBuzzer((3, 'Fizz'), (5, 'Buzz'))
for val in fizzbuzz[1:21]:
... print val
...
1 21 1
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
>>abc = FizzBuzzer((2, 'Ah'), (3, 'Bee'), (5, 'Cee'))
list(abc[25:35])
25 35 1
['Cee', 'Ah', 'Bee', 'Ah', 29, 'AhBeeCee', 31, 'Ah', 'Bee', 'Ah']
>>>
--
Arnaud

Jun 27 '08 #12
On May 12, 9:30*am, Arnaud Delobelle <arno...@googlemail.comwrote:
[...]
# FizzBuzzer in action:
>fizzbuzz = FizzBuzzer((3, 'Fizz'), (5, 'Buzz'))
for val in fizzbuzz[1:21]:

... * * print val
...
1 21 1
^^^^^^^^
Ignore this, it's debugging output
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz>>abc = FizzBuzzer((2, 'Ah'), (3, 'Bee'), (5, 'Cee'))
>list(abc[25:35])

25 35 1
^^^^^^^^^
Same
['Cee', 'Ah', 'Bee', 'Ah', 29, 'AhBeeCee', 31, 'Ah', 'Bee', 'Ah']
--
Arnaud

Jun 27 '08 #13
On May 11, 3:12*am, globalrev <skanem...@yahoo.sewrote:
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?
personally if you're just checking if a modulus result is 0 or not I
would rather do as it looks neat imho.

for i in xrange(1,101):
if not i % 3 and i % 5:
print 'Fizz'
elif i % 3 and not i % 5:
print 'Buzz'
elif not i % 3 and not i % 5:
print 'FizzBuzz'
else:
print i
Jun 27 '08 #14
Ivan Illarionov <iv*************@gmail.comwrote:
>>is there a better way than my solution? is mine ok?

['%s%s' % (not i%3 and 'Fizz' or '', not i%5 and 'Buzz' or '')
or str(i) for i in xrange(1, 101)]

-- Ivan

or, more correctly, if you actually need to "print":

sys.stdout.write('\n'.join('%s%s' %
(not i%3 and 'Fizz' or '', not i%5 aBuzz' or '')
or str(i)
for i in xrange(1, 101)))
I think the variant I came up with is a bit clearer:

for i in range(1,101):
print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else 'Buzz') or i
Jun 27 '08 #15
Duncan Booth wrote:
Ivan Illarionov <iv*************@gmail.comwrote:
>>>is there a better way than my solution? is mine ok?
['%s%s' % (not i%3 and 'Fizz' or '', not i%5 and 'Buzz' or '')
or str(i) for i in xrange(1, 101)]

-- Ivan
or, more correctly, if you actually need to "print":

sys.stdout.write('\n'.join('%s%s' %
(not i%3 and 'Fizz' or '', not i%5 aBuzz' or '')
or str(i)
for i in xrange(1, 101)))

I think the variant I came up with is a bit clearer:

for i in range(1,101):
print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else 'Buzz') or i
More than a bit clearer, IMO. How about
print ('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz') or i
(or perhaps
print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz')) or i
to save looking up the precedence rules) ?
Jun 27 '08 #16
On May 12, 1:30*pm, John Machin <sjmac...@lexicon.netwrote:
Duncan Booth wrote:
[...]
I think the variant I came up with is a bit clearer:
for i in range(1,101):
* *print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else 'Buzz') or i

More than a bit clearer, IMO. How about
* * *print ('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz') or i
(or perhaps
* * *print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz')) or i
to save looking up the precedence rules) ?
Stuff clarity! How about

for i in xrange(1, 101):
print 'FizzBuzz'[4*(i%3>0):4+4*(i%5<1)] or i

--
Arnaud

Jun 27 '08 #17
Arnaud Delobelle <ar*****@googlemail.comwrote:
On May 12, 1:30*pm, John Machin <sjmac...@lexicon.netwrote:
>Duncan Booth wrote:
[...]
I think the variant I came up with is a bit clearer:
for i in range(1,101):
* *print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else
'Buzz') or
i
>>
More than a bit clearer, IMO. How about
* * *print ('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz') or
i (or perhaps
* * *print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz'))
or i to save looking up the precedence rules) ?

Stuff clarity! How about

for i in xrange(1, 101):
print 'FizzBuzz'[4*(i%3>0):4+4*(i%5<1)] or i

--
Arnaud

--
http://mail.python.org/mailman/listinfo/python-list

With no loop:

i=1
exec"print'FizzBuzz'[4*(i%3>0):4+4*(i%5<1)]or i;i+=1;"*100
max

Jun 27 '08 #18
On May 12, 1:59 pm, Arnaud Delobelle <arno...@googlemail.comwrote:
On May 12, 1:30 pm, John Machin <sjmac...@lexicon.netwrote:
Duncan Booth wrote:
[...]
I think the variant I came up with is a bit clearer:
for i in range(1,101):
print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else 'Buzz') or i
More than a bit clearer, IMO. How about
print ('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz') or i
(or perhaps
print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz')) or i
to save looking up the precedence rules) ?

Stuff clarity! How about

for i in xrange(1, 101):
print 'FizzBuzz'[4*(i%3>0):4+4*(i%5<1)] or i
for i in xrange(1, 101):
print 'Fizz'*(i%3<1)+'Buzz'*(i%5<1) or i

--
Paul Hankin
Jun 27 '08 #19
Paul Hankin <pa*********@gmail.comwrites:
On May 12, 1:59 pm, Arnaud Delobelle <arno...@googlemail.comwrote:
>On May 12, 1:30 pm, John Machin <sjmac...@lexicon.netwrote:
Duncan Booth wrote:
[...]
I think the variant I came up with is a bit clearer:
for i in range(1,101):
print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else 'Buzz') or i
More than a bit clearer, IMO. How about
print ('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz') or i
(or perhaps
print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz')) or i
to save looking up the precedence rules) ?

Stuff clarity! How about

for i in xrange(1, 101):
print 'FizzBuzz'[4*(i%3>0):4+4*(i%5<1)] or i

for i in xrange(1, 101):
print 'Fizz'*(i%3<1)+'Buzz'*(i%5<1) or i
I like this, I can imagine plenty of use cases...

....in codegolf

--
Arnaud
Jun 27 '08 #20
On 12 mai, 09:00, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Sat, 10 May 2008 22:12:37 -0300, globalrev <skanem...@yahoo.seescribió:
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?

Is it correct? Did you get at it in less than 15 minutes? If so, then it'sOK.
The original test was not "write the most convoluted algorithm you can think of", nor "write the best program to solve this". It was a *practical* test: if you can't get anything remotely working for such a simple problem in 15 minutes, we're not interested in your services.

(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)
I just can't believe someone applying for a programmer position cannot
provide a sensible anwser in 5 or less minutes.

Jun 27 '08 #21
On 2008-05-12, Paul Hankin <pa*********@gmail.comwrote:
for i in xrange(1, 101):
print 'Fizz'*(i%3<1)+'Buzz'*(i%5<1) or i
Doh! It never occured to me that 'string' * 0 == ''.

--
Grant Edwards grante Yow! An air of FRENCH FRIES
at permeates my nostrils!!
visi.com
Jun 27 '08 #22

"Gabriel Genellina" <ga*******@yahoo.com.arwrote in message
news:op***************@a98gizw.cpe.telecentro.net. ar...
En Sat, 10 May 2008 22:12:37 -0300, globalrev <sk*******@yahoo.se>
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

Jun 27 '08 #23
On Tue, 13 May 2008 03:42:30 +1000, br*****************@gmail.com
<br*****************@gmail.comwrote:
I just can't believe someone applying for a programmer position cannot
provide a sensible anwser in 5 or less minutes.
You should join the recruitment and interview panel in your organization
to test your faith.

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>

Jun 27 '08 #24
Terry Reedy wrote:
"Gabriel Genellina" <ga*******@yahoo.com.arwrote in message
news:op***************@a98gizw.cpe.telecentro.net. ar...
En Sat, 10 May 2008 22:12:37 -0300, globalrev <sk*******@yahoo.se>
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.

Jun 27 '08 #25
<bruno.desthuilli...@gmail.comwrote:
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
Jun 27 '08 #26
Kam-Hung Soh a écrit :
On Tue, 13 May 2008 03:42:30 +1000, br*****************@gmail.com
<br*****************@gmail.comwrote:
>I just can't believe someone applying for a programmer position cannot
provide a sensible anwser in 5 or less minutes.

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.
Jun 27 '08 #27
Gabriel Genellina <ga*******@yahoo.com.arwrote:
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-

Jun 27 '08 #28
Matthew Woodcraft wrote:
Gabriel Genellina <ga*******@yahoo.com.arwrote:
>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.
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.
Jun 27 '08 #29
On May 13, 3:57*pm, John Machin <sjmac...@lexicon.netwrote:
Matthew Woodcraft wrote:
Gabriel Genellina <gagsl-...@yahoo.com.arwrote:
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.

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.
Jun 27 '08 #30
En Tue, 13 May 2008 19:31:03 -0300, Mensanator <me********@aol.com>
escribió:
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>

--
Gabriel Genellina

Jun 27 '08 #31
globalrev schrieb:
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
Jun 27 '08 #32
On May 20, 6:57*am, Wolfgang Grafen <wolfgang.gra...@ericsson.com>
wrote:
globalrev schrieb:


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- 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?
Jun 27 '08 #33
range(1,101), no?

On Tue, May 20, 2008 at 4:46 PM, Sells, Fred
<fr********@adventistcare.orgwrote:
or
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?

--
http://mail.python.org/mailman/listinfo/python-list


--
http://www.badmuthahubbard.com
Oct 3 '08 #34
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?
--
http://mail.python.org/mailman/listinfo/python-list


** Posted from http://www.teranews.com **
Oct 6 '08 #35
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?
--
http://mail.python.org/mailman/listinfo/python-list


Oct 6 '08 #36

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris Green | last post by:
Heyas folks, When does issubclass fail? That's a loaded question so here's my test case (also available at http://cmg.dok.org/code/classimports.tar.gz): directory structure: ../test.py...
1
by: rayt | last post by:
I’m relatively new to XSLT and must admit I’m finding it refreshing, but every now and again something comes along which floors me. Maybe it’s the old imperative language background that is hard to...
27
by: Chess Saurus | last post by:
I'm getting a little bit tired of writing if (a = malloc(...) == NULL) { // error code } I mean, is it really possible that a malloc call could fail, except in the case of running out of...
5
by: FBergemann | last post by:
I use SunOS 5.8, gcc 3.3.2, boost 1.33.1. I have build the entire boost package and try to compile a simple example: #include <iostream> #include <string> #include <boost/regex.hpp //...
0
by: Sells, Fred | last post by:
or for i in range(1,100): print ('fizz','','') + ('buzz','','','','') or i
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.