September 13, 2010

FizzBuzz in Python

FizzBuzz is a stupid test ( trick ) to make people feel
innocent or guilty or
simply not good enough for business demands on programmers skills.
of course it is trivial and easy sot it should not confuse anyone
who has solved at least a programming problem, during his life...

But...
mainly for 2 not so obvious reasons it is a bad test

Firstly
this tests assumes that ones that finds difficulties or taking time to solve it
means that he don't got the skills or he is too slow.
It is wrong because for example many people could have been for some reasons
away from coding for some time so they could have the need for little practice to refresh their memory

Secondly
It can lead to perfect misleadings and misunderstandings
because if somebody writes the fizzBuzz nearly or faster than the typical speed of typing
it is completely stupid to assume that he is a great programmer just because of that.
Simply because someone can solve extremely fast such a trivial "problem" is not enough to
give any label except that one can say
that he may have some ( probably ) recent experience on the exact subject .
Even that assumption without being sure enough.

Generally a simple question will never be enough or form a complete test about
someones abilities or skills .


Please stop giving people labels they don't deserve


Anyway with the power of Python here is my solution to the this fizzbuzz "problem"

Does this makes me more competitive for business than others...???
Bullshit ... of course not
It's just a f@ckin... trivial problem .

and by the way to all those "business" people and their blind followers...
from Peter Tosh
I am that i am!!!



Lyrics -- > http://www.stlyrics.com/songs/p/petertosh7044/iamasiam553530.html
So here is my Python FizzBuzz little code

The first code that natural came in my mind was

def FizzBuzz(n)
for i in xrange(1,n + 1):
if (i % 3) == 0 and ( i % 5 ) == 0 :
print "FizzBuzz"
elif ( i % 3) == 0 :
print "Fizz"
elif (i % 5) == 0 :
print "Buzz"
else:
print i

link --> http://codepad.org/jYSYZK1F

A more simplified one could have been
def fizzbuzz(n):
for i in xrange (1,n+1):
print not ( (i % 3) or (i % 5) ) and "FizzBuzz" or not i % 3 and "Fizz" or not i % 5 and "Buzz" or i

And a little more optimized and simplified one could have been
def fizzbuzz(n):
for i in xrange (1,n+1):
print not i % 15 and "FizzBuzz" or not i % 3 and "Fizz" or not i % 5 and "Buzz" or i


Output with ( n = 100 ) is:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz

No comments:

Post a Comment

Γράψτε εδώ τα σχόλια σας!!!

ΤΙ ΘΑ ΓΙΝΕΙ ΤΟ 2012?