From: Tim Chase on
On 08/06/10 15:37, James Mills wrote:
> On Sat, Aug 7, 2010 at 6:28 AM, geremy condra<debatem1(a)gmail.com> wrote:
>> If I had to wait 5 minutes while a candidate tried to solve this
>> problem I would not hire them.
>
> Yes you do raise a valid point. It should really only take
> you a mere few seconds or so to write a solution to this.
>
> More over, it can be done in just a single line of Python.
>
> 7 if you're not very familiar with Python.

While it *can* be done in one line, I'm not sure it's the most
legible solution. Though I must say I like this one-line python
version:

for i in range(1, 101): print ((i%3==0 and 'fizz' or '') +
(i%5==0 and 'buzz' or '')) or i

(adjust "3" and "5" for your local flavor of fizzbuzz)

I'm not sure I'd hire a candidate that proposed this as a
solution in earnest, but I'd have fun chatting with them :)

-tkc


From: Peter Otten on
Tim Chase wrote:

> On 08/06/10 15:37, James Mills wrote:
>> On Sat, Aug 7, 2010 at 6:28 AM, geremy condra<debatem1(a)gmail.com> wrote:
>>> If I had to wait 5 minutes while a candidate tried to solve this
>>> problem I would not hire them.
>>
>> Yes you do raise a valid point. It should really only take
>> you a mere few seconds or so to write a solution to this.
>>
>> More over, it can be done in just a single line of Python.
>>
>> 7 if you're not very familiar with Python.
>
> While it *can* be done in one line, I'm not sure it's the most
> legible solution. Though I must say I like this one-line python
> version:
>
> for i in range(1, 101): print ((i%3==0 and 'fizz' or '') +
> (i%5==0 and 'buzz' or '')) or i
>
> (adjust "3" and "5" for your local flavor of fizzbuzz)
>
> I'm not sure I'd hire a candidate that proposed this as a
> solution in earnest, but I'd have fun chatting with them :)

You mean you'd go for the candidate who took the conservative approach and
got it right:

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

Well, almost right, but one error per 100 lines at the first try is near-
genius anyway...

Peter

From: Terry Reedy on
On 8/7/2010 7:53 AM, Peter Otten wrote:

>
> You mean you'd go for the candidate who took the conservative approach and
> got it right:
>
> print 1
> print 2
> print 'Fizz'
> print 4
> print 'Buzz'
> print 'Fizz'
> print 7
> print 8
> print 'Fizz'
> print 'Buzz'

Way too verbose. How about
print("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n
etc.

--
Terry Jan Reedy

From: Peter on
On Aug 9, 6:49 am, Terry Reedy <tjre...(a)udel.edu> wrote:
> On 8/7/2010 7:53 AM, Peter Otten wrote:
>
>
>
> > You mean you'd go for the candidate who took the conservative approach and
> > got it right:
>
> > print 1
> > print 2
> > print 'Fizz'
> > print 4
> > print 'Buzz'
> > print 'Fizz'
> > print 7
> > print 8
> > print 'Fizz'
> > print 'Buzz'
>
> Way too verbose. How about
> print("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n
> etc.
>
> --
> Terry Jan Reedy

And to hell with the code being maintainable afterwards? :-)

Personally I would FIRE somebody who produced code like this. Assuming
I was a manager or in a position to hire (I used to be in a previous
life), then I would be looking for somebody who was capable of writing
good, solid and MAINTAINABLE code (love those subjective words? :-)).

Realistically, if the application is anything other than trivial then
it will most likely have somebody poking around in it at some stage
who isn't the brightest spark in the firmament. Anybody who produces
nice, readable and straight forward code in my books gets the tick of
approval.

No offence intended, but anybody who tried to prove how "bright" they
are by producing the least number of (unmaintainable) lines of code
would not get past the first interview - unless they were prepared to
sign a contract that guaranteed they would be available to maintain
the application for its entire lifecycle. Generally (in my experience)
people who write code like this don't hang around long - certainly not
long enough to maintain their monstrosity!

Peter

From: Steven D'Aprano on
On Sun, 08 Aug 2010 17:28:59 -0700, Peter wrote:

> On Aug 9, 6:49 am, Terry Reedy <tjre...(a)udel.edu> wrote:
>> On 8/7/2010 7:53 AM, Peter Otten wrote:
>>
>> > You mean you'd go for the candidate who took the conservative
>> > approach and got it right:
>>
>> > print 1
>> > print 2
>> > print 'Fizz'
>> > print 4
>> > print 'Buzz'
>> > print 'Fizz'
>> > print 7
>> > print 8
>> > print 'Fizz'
>> > print 'Buzz'
>>
>> Way too verbose. How about
>> print("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n etc.
>>
>> --
>> Terry Jan Reedy
>
> And to hell with the code being maintainable afterwards? :-)


I'm pretty sure both Peter Otten and Terry Reedy were being sarcastic and/
or ironic.


--
Steven